How do I detect if an object is rotating CW or CCW?

Get help using Construct 2

Post » Mon Aug 14, 2017 9:07 am

Is there such a function?

I believe Physics behavior has this, but I'm not using that. Basically I want a sprite to play different animations when it's rotating clockwise and counterclockwise (think a car where its front wheels turn to steer). A player-controlled sprite can do this easily by relying on player input, what's a simple way to reproduce the same for an AI-controlled sprite?

Caveat: AI uses "rotate towards position" action, so I don't have separate AI turns right/AI turns left actions I can stick this into.
B
65
S
25
G
19
Posts: 307
Reputation: 14,041

Post » Mon Aug 14, 2017 10:25 am

May be this can help you with ideas
Image
B
17
S
7
G
2
Posts: 45
Reputation: 2,852

Post » Mon Aug 14, 2017 11:31 am

Simply store its angle at the last tick in an instance variable. If the current angle is clockwise of the last angle, it's rotating clockwise, otherwise anticlockwise (or not rotating).

Note if you rotate 270 degrees clockwise, that will count as 90 degrees anticlockwise.
Scirra Founder
B
415
S
248
G
92
Posts: 25,295
Reputation: 200,984

Post » Mon Aug 14, 2017 11:46 am

Ashley, what did you meant under "at the last tick" ?
B
17
S
7
G
2
Posts: 45
Reputation: 2,852

Post » Mon Aug 14, 2017 12:56 pm

B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

Post » Tue Aug 15, 2017 1:40 am

Aha, now I can do away with all the convoluted angle checks I was using. Thanks!
B
65
S
25
G
19
Posts: 307
Reputation: 14,041


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest