# How would you... is turning?

### » Thu Dec 09, 2010 8:53 pm

If you were making your own custom movement(top down), and you wanted to know when the object was turning left, or right... how would you set it up?

My first thoughts were to have the current angle sent to a private variable, and then compare that variable... if its less than current, you have a right turn... etc.

Seems a little complicated, especially on the timing.... any thoughts on a better way?
B
176
S
50
G
200
Posts: 8,637
Reputation: 124,575

### » Thu Dec 09, 2010 9:14 pm

It's pretty straightforward with the "is clockwise" system condition. I through the anglediff in there to make a threshold so that the Sprite isn't always thought to be turning.
[code:2zibx2e6]+ Sprite: Pick by anglediff(.angle, 'oa') Greater than 1
+ System: Angle Sprite.Angle is Clockwise from Sprite ('oa')
// turning right
+ System: Angle Sprite.Angle is Anticlockwise from Sprite ('oa')
// turning left
+ System: Always (every tick)
-> Sprite: Set 'oa' to.Angle
[/code:2zibx2e6]
B
98
S
36
G
132
Posts: 5,525
Reputation: 84,013

### » Thu Dec 09, 2010 9:17 pm

At the end of the event sheet set a pv called "last angle" to .angle. Then use the system compare: "angle is clockwise/counterclockwise of" to check it against the current angle. If the current angle is clockwise to the last angle then it turned right.

Edit: Rojo beat me to it.
B
49
S
10
G
9
Posts: 1,224
Reputation: 8,480

### » Thu Dec 09, 2010 10:24 pm

Thanks guys!
That anglediff, does sound perfect for the timing issue.
B
176
S
50
G
200
Posts: 8,637
Reputation: 124,575

### » Thu Dec 09, 2010 11:16 pm

Oh wow this is one of those times where placement of the events really matters.
If you set the value before you do angledif, nothing will happen.
B
176
S
50
G
200
Posts: 8,637
Reputation: 124,575