Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: artician on March 17, 2012, 04:24:04 PM

Title: Getting direction between two objects [SOLVED]
Post by: artician on March 17, 2012, 04:24:04 PM
I have two objects in my scene.  Both their positions change constantly, and I want to cast a ray from one to the other.  I'm not exactly certain how to derive the direction vector though.  I am using the raycast action, which originates on ObjectA, and from ObjectPosA (for the position variable).  I want to cast directly at ObjectB the entire time, with the goal being to collect information on whatever objects come between the two.
To make it a bit simpler, the two objects are always on a 2D plane, so I really only need to worry about the Y angle.  
Can someone shed some light on what actions I need to use to derive the direction between the two objects and feed that into the Dir variable in my Raycast action?

Things I've tried -
Having ObjectA LookAt ObjectB, but there was no direction variable I could retrieve from this action.
I tried giving the euler Y value from ObjectA while it was using the LookAt action, and adding it to a vector variable to use as my direction, but this did not work.
I tried using GetTransformDirection, but this Action was a bit confusing to me as it seems to want a Direction vector to transform to worldspace, so it did not seem to be what I was looking for either.
Finally, of course, I just used a GetRotation action to derive the vector of ObjectA and feed it directly into the Direction variable for the Raycast, to the same result.

The majority of these attempts usually resulted in my Raycast pointing directly up, rather than at ObjectB.  I'm sure this is an elementary mistake on my part but I'd appreciate any input.

Thank you in advance!
Title: Re: Getting direction between two objects
Post by: justifun on March 18, 2012, 12:54:30 AM
Just thinking outside the box... but what about this.

Add a empty game object to both objects in the center of them.

These will be responsible solely for determining what's between them.

Add a "look at" to each object so that they constantly look at each other.
also add a "get distance" action to determine how far apart they are from each other.
Add a raycast to each of them, and feed the "get distance" variable from the previous step into the distance of the ray cast.  This will create a ever changing "beam" or link between the two objects
Raycast direction will be Z because the two objects area always looking at each other.

Now anything that crosses between the two objects will be able to be seen by either object.

You can use a send event to a game object fsm to send the info back from those empty game objects to either of the original object A or B if needs be too.

I think that should work :)
Title: Re: Getting direction between two objects
Post by: artician on March 18, 2012, 12:25:32 PM
Your suggestion to cast in Z in local space from the object with the LookAt action was exactly what it needed.  Thank you for your help!  :)