- Home /
Car turorial reset vehicle
Hi all!
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?
Answer by AngryOldMan · Mar 18, 2011 at 05:11 PM
you can lock its rotation if it's a rigid body under rigidbody ~> constraints ~> freeze rotation.
Or
in your ResetCar function you can put a transform.rotation feature in there to reset it back to it's normal way up
Answer by Meltdown · Mar 18, 2011 at 07:19 PM
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)));
}
}
Your answer
Follow this Question
Related Questions
car accelerates too slow ? 0 Answers
Vehicle (tank) for my character 1 Answer
Problem Enter and Exit with Vehicle 2 Answers