Hi. i’m currently making a game where my ship moves in 3d space. I’ve hit a problem where the ship rolls over if you spin the ship on it’s Z axis over 90 degrees, so I want to stop it from rotating when it reaches about 65 degrees in either direction. I’ve tried alot of this, but haven’t figured it out so far.
public void Rotate() // boomshackalacka
{
float rStickY = Input.GetAxis("HorizontalRotationP1");
float rStickX = Input.GetAxis("VerticalRotationP1");
if (Input.GetAxis("HorizontalRotationP1") < 0.2)
{
transform.Rotate(new Vector3(0, rStickY, 0) * RotationSpeed * Time.deltaTime);
_model.Rotate(new Vector3(0, 0, -rStickY) * RotationSpeed * Time.deltaTime);
}
if (Input.GetAxis("HorizontalRotationP1") > 0.2)
{
transform.Rotate(new Vector3(0, rStickY, 0) * RotationSpeed * Time.deltaTime);
_model.Rotate(new Vector3(0, 0, -rStickY) * RotationSpeed * Time.deltaTime);
}
if (Input.GetAxis("VerticalRotationP1") < 0.2)
{
transform.Rotate(new Vector3(rStickX, 0, 0) * RotationSpeed * Time.deltaTime);
}
if (Input.GetAxis("VerticalRotationP1") > 0.2)
{
transform.Rotate(new Vector3(rStickX, 0, 0) * RotationSpeed * Time.deltaTime);
}
if ((Input.GetAxis("VerticalRotationP1") == 0 && Input.GetAxis("HorizontalRotationP1") == 0) && _shotTimer > 0.3)
{
transform.rotation = Quaternion.Lerp(_playerBody.rotation, _originalRotation, Time.deltaTime * 10f); //originalRotation får den att kolla rakt fram dirr, vill bryta ut någon axel.
_model.rotation = Quaternion.Lerp(_model.rotation, _originalRotation, Time.deltaTime * 10f);
}
}
All help is greatly appreciated!