How do I determine which direction is my sprite moving to?

0 Favourites
• 5 posts
• So I'm trying to build on an example for grid movements, I need to be able to figure out what direction the sprite is moving to, since I want to be able to change animations, and create a wall block in front of them after they started moving. I am trying to achieve my sprites not overlapping trough each other and not moving on the same place so if I created a block after the sprite has started moving no other sprites could move there at the same time.

Currently I am using a lot of code to determine what direction to move to and "choose(1,2,3,4)" direction so I don't know how I can pick the direction directly because its random.

Basically what I want to do is;

if *sprites started moving to direction x*

--> set animation to x

--> create block at position x

I never added the animations, but I know how to do it by myself if I find a way to determine where and when it started moving.

``https://drive.google.com/open?id=0Bw7sth_-pQTXVjZQdlZyTlNna0E[/code:244fcizz]``
• Try Construct 3

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

Construct 3 users don't see these ads
• At the point the direction is picked then you know which direction, right?

• No I don't because the code says "choose(0,90,180,270)" or a variation of that and it always changes depending of the position of sprite, like for example if i have walls in the north and south the code does "choose(0,180)"

And I have a code for every single possible combination in between a wall at every side, and a wall and no side.

• No I don't because the code says "choose(0,90,180,270)" or a variation of that and it always changes depending of the position of sprite, like for example if i have walls in the north and south the code does "choose(0,180)"

And I have a code for every single possible combination in between a wall at every side, and a wall and no side.

Well after the choose() expression the direction is chosen right?

So that direction should determine the animation..

Maybe to make it easier on yourself, you could set an instance variable on the sprite to the choose() and use that instance variable for setting the animation..

Another way, if this choose sets the bullet direction, you might also be able to add a condition

for each sprite

system compare two values: sprite.bullet.angleofmovement = 180

set animation

• > No I don't because the code says "choose(0,90,180,270)" or a variation of that and it always changes depending of the position of sprite, like for example if i have walls in the north and south the code does "choose(0,180)"

>

> And I have a code for every single possible combination in between a wall at every side, and a wall and no side.

>

Well after the choose() expression the direction is chosen right?

So that direction should determine the animation..

Maybe to make it easier on yourself, you could set an instance variable on the sprite to the choose() and use that instance variable for setting the animation..

Another way, if this choose sets the bullet direction, you might also be able to add a condition

for each sprite

system compare two values: sprite.bullet.angleofmovement = 180

> set animation

Heh, actually I just finished doing that changing the choose() to pick a variable and came back to the thread to see it recommended, and yes it works much better now.