Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: cats00eye on May 08, 2018, 09:00:11 AM

Title: Smooth look at direction 2d? [SOLVED]
Post by: cats00eye on May 08, 2018, 09:00:11 AM
Essentially, I just want a 2d sprite to rotate to face its direction of motion.

There doesn't seem to be a 2d equivalent to the smooth look at direction action. Looking at the script for that action, it seems to depend on quaternions, which use vector3 as parameters. How would one go about editing this for 2d? Alternatively, are there any downsides to using the 3d action in a 2d project, setting the z-value to 0?
Title: Re: Smooth look at direction 2d?
Post by: djaydino on May 08, 2018, 03:47:55 PM
Hi.
How are you getting the direction that you wish to look at?

if it is a vector 2 , use 'get Vector2 XY' and get the 2 floats x,y
Then use 'set vector 3 xyz'
and use the floats from the vector 2.
Title: Re: Smooth look at direction 2d?
Post by: cats00eye on May 08, 2018, 06:22:37 PM
Thanks for the reply. I'm playing with flocking ideas, so the sprites are changing velocity vectors based on the vectors of their neighbours. It seems to be working so far, apart from their rotation.

No, I tried your suggestion, but whichever dimension I leave out of the 3d rotate action, they start rotating in three dimensions - quite pretty, but not what I want.
Title: Re: Smooth look at direction 2d?
Post by: djaydino on May 09, 2018, 09:48:10 AM
Hi,
Can you use Smooth look at 2d maybe?
And set the 'Target Position 2d' instead of an object?

if that does not work can you show a video, sample scene or something from whats happening and/or what you are trying to achieve?

You can pm it to me if you don't want to show in public.
Title: Re: Smooth look at direction 2d?
Post by: cats00eye on May 09, 2018, 11:49:55 AM
Solved, thanks! I was up to my knees in arctangents when I got your reply. Smooth look at is what I first started with and dismissed it when it didn't work, but the solution should have been obvious: add the game object's velocity to its current position and use that as a look-at point. Very satisfying. Thanks again!
Title: Re: Smooth look at direction 2d?
Post by: djaydino on May 09, 2018, 04:25:52 PM
Hi.
No problem, happy to help :)