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;