Reset physics of a gameobject

I’m working on a racing game and when I respawn my motorbike at a checkpoint location, the vehicle is still moving. How can I reset the physics ? I try this code, but it doesn’t work :

	rigidbody.velocity = Vector3.zero;
	rigidbody.angularVelocity = Vector3.zero;
	rigidbody.Sleep( );

That should do it. Do you apply force with forcemode.VelocityChange and forgot to set a Speed variable to zero as well? If not you could try setting the rigidbody isKinematic = true; for a frame and then false the next.

It works now, I’ve fogotten the wheels. But when I wake up the set, I can’t move the motorbike.

	rigidbody.Sleep( );
	for(var w : Wheel in animWheels)
	{
		w.collider.rigidbody.Sleep();
	}

	yield WaitForSeconds(1.0);

	...

	rigidbody.WakeUp( );
	for(var w : Wheel in animWheels)
	{
		w.collider.rigidbody.WakeUp();
	}

I’m wrong. The rigidbody from w.collider is not accesible (null ?)

I’ve tried to set isKinematic to true and then to false in the Update method but it doesn’t work yet.

I may be wrong, but I don’t think you need rigidbody.Sleep() unless you are doing something special.

What I believe you DO need to do is something like this:

rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;

var rigidbodies = gameObject.GetComponentsInChildren(rigidbody);
for (var rb : Rigidbody in rigidbodies)
{
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
}

I’ve got this error with your code :
GetComponentsInChildren requires 1 argument

I fixed it but it doesn’t work :
var rigidbodies = gameObject.GetComponentsInChildren(Rigidbody);