How do I detect the direction of an instance?

Get help using Construct 2

Post » Wed Oct 15, 2014 9:32 pm

Hi,

I'm experimenting with a vertical space shooter and I have enemy ships moving downwards with bullet and sine wave behaviours. I want to detect whether an enemy ship instance is moving left or right so that I can change the sprite accordingly. How do I do this without using the enemy ship's angle (by design they always face down)?

Thanks :)
B
3
Posts: 2
Reputation: 179

Post » Wed Oct 15, 2014 9:41 pm

@GODGE are the enemy ships actually moving or are they stationary in one place. a screenshot would help
B
13
S
5
G
1
Posts: 119
Reputation: 2,292

Post » Wed Oct 15, 2014 9:42 pm

You make some variables, oldx, newx, oldy, newy, and set newx,y to current x,y every tick.
Then if newx is greater than oldx you know its going right, less left, newy >oldy, down, etc.
If newx, or newy is different to oldx, or oldy, you set oldx to newx, and oldy to newy.

Or, use a dummy for the graphic so that you can use the angle.
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Wed Oct 15, 2014 10:19 pm

@newt Thanks newt, works a treat :)
B
3
Posts: 2
Reputation: 179


Return to How do I....?

Who is online

Users browsing this forum: NN81, Syazanie Amirin and 7 guests