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

Just started using Construct 2? Post your questions here

» Wed Dec 23, 2015 11:57 pm

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.

Code: Select all
`https://drive.google.com/open?id=0Bw7sth_-pQTXVjZQdlZyTlNna0E`
B
10
S
2
G
1
Posts: 51
Reputation: 878

» Thu Dec 24, 2015 2:14 am

At the point the direction is picked then you know which direction, right?
B
53
S
21
G
95
Posts: 2,449
Reputation: 56,113

» Thu Dec 24, 2015 11:58 am

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.
B
10
S
2
G
1
Posts: 51
Reputation: 878

» Thu Dec 24, 2015 12:18 pm

littanana wrote: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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

» Thu Dec 24, 2015 1:35 pm

LittleStain wrote:
littanana wrote: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.
B
10
S
2
G
1
Posts: 51
Reputation: 878