Description
The ClearForces
method is used to clear any accumulated linear forces that have been applied to a Rigidbody
during the current physics frame but have not yet been applied to the physics body. This is useful for resetting the forces on a Rigidbody
if you need to ensure that no unintended forces affect the object in the next physics update.
Usage
To use the ClearForces
method, simply call it on an instance of a Rigidbody
component. This will remove any forces that have been applied using methods like ApplyForce
or ApplyForceAt
that have not yet been processed by the physics engine.
Example
// Example of using ClearForces
Rigidbody myRigidbody = new Rigidbody();
// Apply some forces
myRigidbody.ApplyForce(new Vector3(10, 0, 0));
myRigidbody.ApplyForceAt(new Vector3(0, 10, 0), new Vector3(1, 0, 0));
// Clear the forces before the physics update
myRigidbody.ClearForces();
// Now the Rigidbody will not have any of the previously applied forces affecting it in the next physics frame.