# Understanding the direction of movement of an actor

Member, PRO Posts: 98

Hello guys,
I'm working on a new game and we're trying to work with an isometric view. I already solved (apparently) the overlapping issue and it looks like the actors move in a tridimensional space.
Our animator is working on 5 walk cycles for each character, one for every direction (8 in total: 0,45,90,135,180,225,270,315. Of course some of these will just be flipped).
While it's pretty clear how to switch animations for my character, as the player controls it, I'm not sure how to detect the angle (and therefore the animation I need) for the enemies. The enemies basically moves towards the character contantly, with this behavior here:

I guess I need to use the vectorToangle function somehow, but I can't understand how to detect if the enemy is going down, up, down-right etc...

I think it should be easy, but for some reason I can't figure it out. Hope someone can help me! Thank you!

Wonder Maru: casual games for casual people. www.wondermaru.com

• London, UK.Member Posts: 12,822

I'm not 100% sure I understand the question . . . ?

Does the NME also have 8 directions (0°, 45°, 90°, 135°, 180°, 225°, 270° and 315°) ?

• Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,925

There's probably a simpler way I'm just not thinking of to determine the direction an actor is moving but here's one way:

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• London, UK.Member Posts: 12,822

@tatiang said:
There's probably a simpler way I'm just not thinking of to determine the direction an actor is moving . . .

More simply (but basically echoing your idea) would be:

(vectorToAngle (Linear Velocity X, Linear Velocity Y))

If you want to normalise the return values to 0-360 (rather than 0 to 180 & -180 to 0) just stick %360 on the end . .

(vectorToAngle (Linear Velocity X, Linear Velocity Y))%360

• Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,925

@Socks that's what I was forgetting. I tried self.Position.X/Y but it was Linear Velocity I was looking for.

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• London, UK.Member Posts: 12,822
edited June 2016

@tatiang said:
@Socks that's what I was forgetting. I tried self.Position.X/Y but it was Linear Velocity I was looking for.

It's basically the Pythagorean theorem, square the X ('a' in the image below) and square the Y ('b' in the image below) - add them up - and it'll give you the square of the other side.

• Member, PRO Posts: 98

Hey guys, awesome! Thank you for the quick answer!
I'm gonna try this right away!

Will update with the result asap

Wonder Maru: casual games for casual people. www.wondermaru.com

• Member, PRO Posts: 98

ok, quick update. Seems to be working. There's still something strange going on, but I need to see this once I'll have the final animation frames (currently I'm using just 1 png for each position and it's kinda hard to understand if the effect is really working or not).

Thank you so much for now, I'll post an update, maybe a video or a gif with the animations

Wonder Maru: casual games for casual people. www.wondermaru.com