- Home /
Rigidbody has zero velocity but still moves
Im trying to slow down a rigidbody attached to something with a configurable joint with addforce. my addforce code works perfectly to stop a lone cube with this code:
rigidBody.AddForce(rigidBody.mass,-rigidBody.velocity), ForceMode.Impulse);
rigidBody.AddTorque(Vector3.Scale(rigidBody.inertiaTensor,-rigidBody.angularVelocity), ForceMode.Impulse);
but with the joint it only slows it down. even setting the velocity and angular velocity to 0, and it showing 0 in the inspector, it still moves.
Is there anything I can do about this?
Answer by xxmariofer · Nov 20, 2020 at 10:38 AM
Well, this doesnt look like an easy task, in unity doesnt exist something like a latefixedupdate or something like that. obviusly joints affect your rigidbodies so even if you set the rigidbody velocity to 0 in the fixedupdate AFTER the fixedupdtae all the physics get calculated (including the joint forces) as stated here: https://docs.unity3d.com/Manual/ExecutionOrder.html#InBetweenFrames if you dont want the rigidbody to be affected bythe joints forces you will have to disable the joint
okay thnx, but is there any possible way to cancel out the force from the joint? If there is some way to see the force on the rigid body caused by the joint?
im using target rotation on the joint, so i'd think that there'd be a way to find out the force from that and the spring settings.
Answer by MurphyMurph_21 · Nov 20, 2020 at 07:32 AM
@mellooow9 maybe if you remove the ForceMode.Impulse
because that is gonna cause it to force move your object
no, its pushing in the opposite direction of its movement to stop it, and it works, it just won't work on joints. and when i set the velocity directly, I did remove the whole addforce part.
Your answer
Follow this Question
Related Questions
How to create a freely swinging "rope" of modifiable size between two rigid bodies? 0 Answers
Setting a delay before dashing. 1 Answer
Why can't I get AddForce or Velocity work? 2 Answers
Rigidbody not calling OnCollisionEnter 1 Answer
Joints vs Mass 0 Answers