Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Box2d: Make object rotation stop — Gideros Forum

Box2d: Make object rotation stop

ZizanymanZizanyman Member
edited August 2015 in General questions
I am trying to create a box2d ball that rolls along the ground when the screen is tapped. In my OnMouseDown function, i have this:
ball.body:setAngularVelocity(10)
I wanted it to stop rotating when you lift up your finger, so I put this in my OnMouseUp function:
ball.body:setAngularVelocity(0)
I tried this out, however, when I release my finger, it only slows the ball down. Shouldn't it make it stop completely, since it is basically setting the angular velocity of the object? Or am I missing something here?

Comments

  • Now I tried using ApplyAngularImpulse, and I applied the negative of that on mouse up. This stopped the object completely. It seems to me that ApplyAngularImpulse and setAngularVelocity should switch names, since the former sets the speed of rotation, and the ladder applies a temporary force to it.
  • totebototebo Member
    edited August 2015
    AngularVelocity affects only the current rotational force of a Body. If you set it to 0 the rotation will stop, but if it's in contact with another object, friction can make it rotate again or, if there isn't enough friction, it could slide on the surface without rotating. To stop the ball with AngularVelocity the friction would need to be high and you'd need to set AngularVelocity continuously rather than just once, or set LinearVelocity to 0 if on a flat surface.

    AngularImpulse (and impulses in general) tend to give more natural behaviours, so I'd stick with using them if that works in your game.

    My Gideros games: www.totebo.com
Sign In or Register to comment.