I have an node in space (no angular dampening, no friction, no gravity) and I apply a torque to it (20 newton meters) over 1 second. It begins to spin and will continue forever. If I apply an inverse force (-20 newton meters) it comes to a complete stop.
If I don't know how much angular torque was applied initially (for instance it collided with another object), how can I determine what the inverse torque to apply would be in order to bring the object to a stop? I tried angularVelocity*mass, and this is close... but always a little shy (like I'm missing something):
-physicsBody!.angularVelocity*physicsBody!.mass
How can I determine Angular Momentum (torque) to use to remove all object rotation?
p = m*v. With a bit of a simplification, angular momentum (L) is defined as the distance of the object from a rotation axis multiplied by the linear momentum: L = r*p or L = mvr.
The angular momentum of the object going in a circle may be expressed in terms of the angular velocity (w) by using v = rw in the definition L = rmv. Substituting for v, we get L = mr2w. But we also said L = Iw, where I is the rotational inertia. So for the case of the object of mass m at radius r, I = mr2.
Angular momentum is defined as: The property of any rotating object given by moment of inertia times angular velocity.
In my games I use active braking to manage stopping a node's motion over time. I do this in the update() function. For your requirements, I present this answer:
let X = -0.2 // This needs to be customized by your needs .. how fast you want to stop.
var need_braking_list : [SKSpriteNode] = [] // Append your spinning nodes here
override func update() {
for (index,node) in need_braking_list {
// We're almost stopped, so force a stop or this goes on forever.
if node.physicsBody?.angularVelocity < 0.1 &&
node.physicsBody?.angularVelocity > (-0.1)
{
node.physicsBody?.angularVelocity = 0
need_braking_list.removeAtIndex(index)
// Apply some braking ... screeech
} else {
let impulse_factor = node.physicsBody?.angularVelocity * (X)
node.physicsBody?.applyAngularImpulse(impulse_factor)
}
}
}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With