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 ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

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
91
S
31
G
103
Posts: 5,234
Reputation: 67,754

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
44
S
9
G
9
Posts: 1,222
Reputation: 8,245

Post » Thu Dec 09, 2010 10:24 pm

Thanks guys!
That anglediff, does sound perfect for the timing issue.
Image ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

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 ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests