How do I Detect if an object has made a full rotation

Get help using Construct 2

Post » Wed Mar 25, 2015 5:06 pm

Greetings all! I'd like to detect when an object has made a full rotation and am trying to figure out the best way to do that.

The context is a physics object which you knock into the air, and if you get some spin on it I'd like to assign points every time it does a complete 360 rotation.

My initial thought was to detect the object's angle as soon as it gets airborn, then listen for every time its angle is once again equal to that starting angle, but since the angle is a float it will never be exactly equal (that method also doesn't take into account if it switches spin directions for whatever reason)

Other suggestions?

Edit: note I'm using the Chipmunk plugin for the physics object
Posts: 87
Reputation: 1,112

Post » Wed Mar 25, 2015 5:34 pm

Keep track of the angle change as soon as the object get airborn. You will need two instances variables, "lastTickAngle" and "deltaAngle".
Object gets airborn -> set lastTickAngle to object angle, set deltaAngle to 0
Every tick -> Add (lastTickAngle - Object angle) to deltaAngle
If Abs(deltaAngle) >= 360 -> Add point, add 360 or subtract 360 to deltaAngle
Posts: 1,027
Reputation: 21,114

Return to How do I....?

Who is online

Users browsing this forum: blackhornet and 3 guests