Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: derkoi on June 10, 2013, 03:10:38 PM

Title: Add force from Raycast direction?
Post by: derkoi 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?
Title: Re: Add force from Raycast direction?
Post by: Lane 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?
Title: Re: Add force from Raycast direction?
Post by: jeanfabre 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

Title: Re: Add force from Raycast direction?
Post by: derkoi 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.  :)
Title: Re: Add force from Raycast direction?
Post by: derkoi 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
Title: Re: Add force from Raycast direction?
Post by: Lane 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.
Title: Re: Add force from Raycast direction?
Post by: derkoi 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.
Title: Re: Add force from Raycast direction?
Post by: jeanfabre 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
Title: Re: Add force from Raycast direction?
Post by: derkoi on June 21, 2013, 07:46:16 AM
I get the direction from the raycast which fires forward from the player object
Title: Re: Add force from Raycast direction?
Post by: jeanfabre 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