I'm working on a test game with the car turorial, but I've got a little problem. When my car jumps over a ramp and flips, it doesn't have a way to reset itself. I created a new statement in the CarController:
if (Input.GetKeyDown(KeyCode.F))
{
drivetrain.ResetCar ();
}
And this void in the drivetrain:
public void ResetCar ()
{
}
But now I'm lost. How can I make the car rise 3 meters and reset it's roll?
Well assuming your car steers left and right around the Y axis, to reset its roll/pitch you need to reset only the X and Z axes.
On your car script, store the car's original rotation transform into a variable.
i.e
private float _originalRotX;
private float _originalRotZ;
void Start () {
_originalRotX = transform.rotation.x;
_originalRotZ = transform.rotation.z;
}
void ResetCar()
{
// Move the rigidbody up by 3 metres
transform.Translate(0, 3, 0);
// Reset the rotation to what it was when the car was initialized
transform.rotation = (Quaternion.Euler(new Vector3(_originalRotX, transform.rotation.y, _originalRotZ)));
}
}