So I’m making a stunt car game. I got the car moving, and there is a script that detects if its on the ground if not. If not on the ground, you can use your arrow keys to flip the car in different directions. One problem though,
This is my rotation code:
if (!onGround)
{
//init
float verticalFlip = 0;
float horizontalFlip = 0;
//get input
if (isPlayer)
{
verticalFlip = verticalFlipSpeed * Input.GetAxis("Vertical");
horizontalFlip = horizontalFlipSpeed * Input.GetAxis("Horizontal");
}
//flip
rigidbody.AddTorque(transform.up * horizontalFlip);
rigidbody.AddTorque(transform.right * verticalFlip);
}
}
It works great, but the vertical flip causes the car to flip like its on a turntable, instead of doing a barrel roll. Is there a way to make it rotate around its local z axis?