If I don’t know how much angular torque was initially applied (e.g. it collides with another object) ), how do I determine what reverse torque is applied to stop the object? I tried angularVelocity* quality, which is close…but always a bit shy (like I missed something):
-physicsBody!.angularVelocity*physicsBody!. mass
How to determine the angular momentum (torque) used to remove all rotations of the object?
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< br />} else {
let impulse_factor = node.physicsBody?.angularVelocity * (X)
node.physicsBody?.applyAngularImpulse(impulse_factor)
}
}
}
Hope this helps!
I have a node in space (no angular damping, no friction, no gravity) and I apply a torque (20 Newton meters) in 1 second. It It starts to rotate and will continue forever. If I apply a reaction force (-20 Newton meters), it will stop completely.
If I don’t know how much angular torque was initially applied (e.g. it is with Another object collision), how do I determine what reverse torque is applied to stop the object? I tried angularVelocity* quality, which is close…but always a bit shy (like I missed something):
-physicsBody!.angularVelocity*physicsBody!. mass
How to determine the angular momentum (torque) used to remove all rotations of the object?
In my game, I use active braking to manage the movement of nodes over time. I do this in the update() function. According to you Request, I put forward this answer:
let X = -0.2 // This needs to be customized by your needs .. how fast you want to stop.< br />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 !