How do I get the X and Y Velocity of a path-finding sprite ?

Get help using Construct 2

Post » Mon Aug 04, 2014 9:19 am

Hello Guys !

It is my first time on this forum... I've been using Construct 2 for a couple of days now and I enjoy it a lot !

However, I came here to ask for some help because I am stuck on something and I couldn't find the answer on the forums...

I am trying to set 4 different animations to a sprite with a path finding behavior, depending if he is moving rater towards X+, X-, Y+ or Y-

I have tried to add physics and custommovement behaviors to have velocity X and velocity Y expressions but it seems that the path-finding movement is independent from the other movement behaviors (in both cases velocity X and Y returns 0 even if the sprite is moving along its path)

Do you guys have any idea on how to fix this ? I am pretty newbish to C2 :?

Thank you for your kind help ;)
B
5
Posts: 11
Reputation: 231

Post » Mon Aug 04, 2014 9:44 am

Yeah, behaviours aren't able to use the specific values of other behaviours.

Do you need the speed that the sprite is moving, or just the direction?

If it's just direction, and assuming that object is moving without diagonals, then the easiest way is to record the sprite's current X and Y every tick that it's moving (use instance variables). Then, at the beginning of the tick, compare its current X/Y (from its properties) to its old X/Y (from its variables), then see if X/Y is greater or smaller than the old values, to determine in which direction it's moving. Once you've got that all done, update the variables at the end of the event to get ready for the next tick.
B
57
S
15
G
11
Posts: 912
Reputation: 12,606

Post » Mon Aug 04, 2014 9:48 am

I only need the direction. I'll try to do what you said. Thank you !
B
5
Posts: 11
Reputation: 231

Post » Mon Aug 04, 2014 10:57 am

Here what I've done. However, it doesn't work (probably because of the Wait action). I couldn't really figure out where to place the assign oldX and oldY to then compare it in real time with X and Y...

Image

EDIT :

It Finally works. Here is the event sheet :

Image

Thank you very ;uch ! :D
B
5
Posts: 11
Reputation: 231


Return to How do I....?

Who is online

Users browsing this forum: Laura_D and 22 guests