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

0 favourites
  • 4 posts
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • 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

  • 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.

  • I only need the direction. I'll try to do what you said. Thank you !

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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...

    EDIT :

    It Finally works. Here is the event sheet :

    Thank you very ;uch !

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)