0 Favourites

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

  • 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

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
167 14,489
DMT2005's avatar
Unread sticky
1 Favourites
C2 Games made with CocoonIO
136 89,817
minhcuong's avatar
Unread hot topic
99 10,136
karshinkoff's avatar