playMaker

Author Topic: Add force from Raycast direction?  (Read 5503 times)

derkoi

  • Full Member
  • ***
  • Posts: 187
Add force from Raycast direction?
« on: June 10, 2013, 03:10:38 PM »
I've used a raycast for a Gun instead of spawning bullets. I'd like to add force to objects that are shot by the raycast but I can think how I could add the correct force Vector from the direction of the raycast? Can anyone help please?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Add force from Raycast direction?
« Reply #1 on: June 10, 2013, 03:31:30 PM »
Are you only trying to affect one target or make a big pulse effect that hits several objects or multiple objects in a line?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force from Raycast direction?
« Reply #2 on: June 11, 2013, 01:45:44 AM »
Hi,

It depends how you generated the rayCast, but that should not be difficult, you want to add a force at the hit point of contact, but I guess your problem is that you use RayCastFrom GameObject right?

 in that case, getting the direction of the ray as a vector3, use the following action: TransformDirection

tell which local axis you are using ( 1,0,0 if you are firing on the positive x axis)

is that what you are after?

bye,

 Jean


derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Add force from Raycast direction?
« Reply #3 on: June 11, 2013, 01:00:33 PM »
Thanks for the replies.

I'm firing a raycast from a game object using the Raycast action. I then send a 'damage' message to any object I hit, spawn a blood splat or ricochet object at the hit point & add force at the hit point. It's the direction of the raycast I need to put in the add force so it throws the enemy/object backwards.

I'll give the transform direction a try.  :)

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Add force from Raycast direction?
« Reply #4 on: June 11, 2013, 02:20:11 PM »
I tried the transform Direction but it doesn't seem to work, it's throwing the objects in all directions.  :o

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Add force from Raycast direction?
« Reply #5 on: June 11, 2013, 02:36:16 PM »
Are you using rigidbodies?

I could tinker around and make an example, but I'm not sure if I can squish it in this week.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Add force from Raycast direction?
« Reply #6 on: June 11, 2013, 03:08:18 PM »
Yeah i'm using rigid bodies & it's working fine. Just the direction in which the rigidbodies are thrown is not away from the gun.
« Last Edit: June 12, 2013, 04:48:05 AM by derkoi »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force from Raycast direction?
« Reply #7 on: June 21, 2013, 01:27:48 AM »
Hi,

 How do you get the direction to begin with? what action are you using?

bye,

 Jean

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Add force from Raycast direction?
« Reply #8 on: June 21, 2013, 07:46:16 AM »
I get the direction from the raycast which fires forward from the player object

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force from Raycast direction?
« Reply #9 on: June 24, 2013, 06:45:31 AM »
Hi,

 I think you are getting confused with the direction of the ray cast and the direction of the hit normal.

 to get the direction of the raycast ( when you use rayCast from gameObject for example), you need to use the "Transform Direction" and in the local Direction put the axis. so if your gameObject fire along its y axis, you need to put (0,1,0) in the local Direction.

 Yes?

bye,

 Jean