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
58
S
25
G
19
Posts: 304
Reputation: 13,858

Post » Mon Aug 14, 2017 10:25 am

May be this can help you with ideas
Image
B
15
S
7
G
2
Posts: 42
Reputation: 2,755

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
408
S
242
G
92
Posts: 24,888
Reputation: 198,582

Post » Mon Aug 14, 2017 11:46 am

Ashley, what did you meant under "at the last tick" ?
B
15
S
7
G
2
Posts: 42
Reputation: 2,755

Post » Mon Aug 14, 2017 12:56 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

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
58
S
25
G
19
Posts: 304
Reputation: 13,858


Return to How do I....?

Who is online

Users browsing this forum: flemmig, work3 and 20 guests