- Home /
Remove all forces on a wheel Collider
Hi all,
I have a simple vehicle that I wish to remove all forces from when I respawn it. I'm using 4 wheel colliders. Forward force is applied by using wheelCollider.motorTorque and braking force is done by brakeTorque. I can get the vehicle to respawn and set it's velocity to zero, but there's often some residual forces working on the wheels. From what I've read, the WheelCollider.rpm is a read only function. Is there any way to instantly set it's WheelCollider.rpm == 0?
Answer by Edy · Nov 30, 2010 at 10:12 AM
You can instantly force the rpm to zero by setting an infinite braking torque:
WheelCollider.brakeTorque = Mathf.Infinity;
However, those residual forces don't come from the rpm. For instance, when riding over a bump the first frame the wheel interpolates the bump there's no force applied. The next frame, as result of the calculations, the proper force is applied to the rigidbody. If a respawn occurs exactly in the middle, then the force will be applied right after respawning.
You should be able to disable the effects of those occasional forces by briefly making the rigidbody as kinematic after respawning. Something like this:
function FixedUpdate() { // (if the vehicle has been respanwed this frame, // then a variable respawned is set to true)
if (respawned)
{
wheelCol.brakeTorke = Mathf.Infinity; // Repeat for all wheelcolliders
rigidbody.isKinematic = true;
respawned = false;
}
else
{
rigidbody.isKinematic = false;
// (do the torque calculations here as usual)
}
}
I know it's an old post but It caused me a bug on android. Mathf.Infinity give the WheelColliders NaN as rpm. Use float.MaxValue.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084118im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Hovercraft Physics Problems 1 Answer
Making a paper like object on Unity. 2 Answers
Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers
Make object stick to the ground in 2D 2 Answers
How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers