I’m currently working on a rocket ship script, and I want it to clamp rotation. It’s also following my mouse and moving towards it on the X-axis. It is constantly moving up on the Y-axis. I’ve been confused with this issue for a while now. Here is my code:
void FaceMouse()
{
Quaternion rotation = transform.rotation; //Right here is the beginning of the attempt to add a clamp.
if (rotation.z > 180)
{
rotation.z = rotation.z = 360;
}
rotation.z = Mathf.Clamp(rotation.z, -40f, 40f);
transform.rotation = rotation; // This is the end.
Vector3 mousePosition = Input.mousePosition;
mousePosition = camera.ScreenToWorldPoint(mousePosition);
directionX = (mousePosition - transform.position).normalized;
directionY = transform.position.normalized;
transform.up = directionX;
}