How would you... is turning?

For questions about using Classic.

Post » 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?
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » 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
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » 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
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Thu Dec 09, 2010 10:24 pm

Thanks guys!
That anglediff, does sound perfect for the timing issue.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » 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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests