Clearing/Resetting Physics?

Hi,

I’m wondering if it’s possible to completely clear out any velocity/force/whatever that’s working on a rigid body object?

I can do setLinearVelocity([0,0,0]) and it works just as I’d like (I think). But…

It’s seeming like setAngularVelocity([0,0,0]) isn’t working on a rigid body object. Other values have the intended effect, but I can’t clear the object’s angular velocity. If I use very small values (like 0.01) it’ll do it, but I’d really like to be able to set it all to 0.

Is there a way to do this?

-Sam

What I do is set the linear velocity, then immediately set the opposites values to cancel out the motion.
setLinearVelocity((1,1,1))
setLinearVelocity((-1,-1,-1))
This removes any momentum.

What I would do is just reset the linV like you did and then just reset the orientation.

own.setLinearVelocity([0,0,0])
own.localOrientation = [[1,0,0],[0,1,0],[0,0,1]]

Hmmmmm I tested it…and it seems that in order to stop the rotation all together you would need to set the angular velocity.

own.setLinearVelocity([0,0,0])
own.localOrientation = [[1,-0,0],[0,1,-0],[0,0,1]]
own.setAngularVelocity([0.0001,0.0001,0.0001],1)

I checked this out aswell, seting the angular velocity to 0 on all axis, doesn’t make any changes, applying the objects negative angular velocity just reverses its rotations (which makes sense), no idea why zero can’t be used for the angular velocity though =/

Ignore that, applying an angular velocity of zero does indeed act correctly, the thing is, the object continues to rotate until that velocity is matched, for example… If an object has an angular velocity of 1.0 on the z-axis, and then you set the angular velocity to zero, the object won’t stop rotating straight away as the velocity is reduced until it hits zero, so it will slowly stop rotating. Heres some debug info showing this:

It makes sense now, as when you set the velocity with a different value it reacts straight away, but with zero you are applying no angular velocity, but the object will continue to spin because of previous forces applied to it. Altough it sounds confusing, this is correct behaviour for Bullet (or any physics library).

To stop an object rotating straight away, you will have to set a low angular velocity such as 0.00001 and then reset its angular velocity to zero, the changes will be unoticable :slight_smile:

Thanks to everyone who took the time to respond, but my question still remains unanswered. Believe me, I’ve picked my way through the API and I’ve got a pretty decent knowledge of basic physics.

@PhilB: Momentum is literally just MV, or mass*velocity. Setting velocity to 0 also removes momentum, and your “method” will just end up setting the Linear velocity to -1,-1,-1. We’re setting the velocity directly to the values, not adding any velocity.

@Sunjay03: Like I said in my original post, I know that setting it to very low values is “close” to what I want, but it’s not exactly what I want.

@Hendore: I’m not sure you’re understanding how simulated “physics” work. First of all, in the real world, you never set velocity directly, you apply forces, which can result in acceleration or torque, which results in angular acceleration.

In a computer simulation, you have the ability to set velocity directly. If no other forces are acting on the object, this should stay the velocity. This seems to work for linear velocity, but not angular velocity, which seems to be a BUG, not “how it should work.”

The slowly lowering angular velocity that you’re seeing is the result of rotation damping, NOT the function that you’re applying. setAngularVelocity([0,0,0]) literally has no effect.

Anyone with more than just a hunch know anything about this?

-Sam

unfortunately this is quite an old ongoing problem… it’s been brought up quite few times on this forum over the years with no clear solution. Maybe Moguri or Benoit could have a look at it when they have some time.

Try to cancel physics in this order: AngularVelocity, LinearVelocity, localOrientation, position

This is working for me:

            o = scene.objects['Suzanne']
            o.setAngularVelocity((0,0,0))
            o.setLinearVelocity((0,0,0))
            o.localOrientation=(0,0,0)
            o.position = (0,7.35,4)

thanks for necro’ing this thread, real big help :+1:

but it is known that in older versions of bge, clearing angular velocity doesnt work, like in 2.74 which i use.