Resetting AI car after it flips over

I am working on a car racing game. For resetting a car if it flips over I am using the code given below. It works perfectly for player car by pressing “r” as input. But if player car collides with AI car the AI car flips over the resetting should happen automatically.

I am saving the AI cars transform every frame till it is on the ground. When it flips over I am giving the position from this saved transform so that it gets there after resetting.I am using Quaternion.identity for rotation(refer below code). But the AIcar after resetting remains in its previous state(wheels moving and everything) which is leading to wierd behaviour after reset.
Is there any way to neutralize everything related to the car(all its physics related parameters) during reset?

Also is there any way to use Sleep() functionality for stopping execution of a particular piece of code for some time?

the code for reset:

rigidbody.velocity = new Vector3(0f, 0f, 0f);
Vector3 a = transform.localRotation.eulerAngles;
a.x = 0;
a.y = Mathf.Repeat(a.y + Input.GetAxis(“Horizontal”) * 5f, 360f);
a.z = 0;
transform.localRotation = Quaternion.Euler(a);
transform.localPosition = savedtransform.position + Vector3.up;

Yes, there is a way :), make your rigidbody kinematic, being kinematic makes the object unaffected by physics :slight_smile:

deactivate the object/script could deactivate its functionality :slight_smile:

Hope it helps! :wink:

Not sure but have you looked at using Coroutines?

Thanks for the replies guys. Making the object kinematic is working wonderfully :smile:

For the sleep thing I have currently used a counter which is doing the job but I think Ill look into coroutines as well. It is a better way of doing things(less bugs :P)

I am a colleague of iceherosubzero btw!