I am trying to make a space ship tilt upwards when it travels upwards or tilt downwards when it falls but I'm stuck this is what I have so far
if (Input.GetKey(KeyCode.Space)) //If spacebar pressed
{
playerRb.AddForce(Vector3.up * floatForce, ForceMode.Impulse); // Add force upwards to player
}
// Rotates upwards
if (Input.GetKey(KeyCode.Space))
{
if (transform.rotation.x != -maxRotation)
{
transform.Rotate(-rotationSpeed, 0f, 0f * Time.deltaTime);
transform.Rotate(-maxRotation, 0f, 0f);
}
}
It just spins infinitely when I press down on the space bar...
Any help? Thank you