Question by
DireSloth · Mar 18, 2018 at 09:21 PM ·
camera rotateclamped rotation
How do I clamp this camera rotation?
Hello, folks, I'm an extremely new to coding and am trying to create the simplest conceivable mouselook script.
using UnityEngine;
using System.Collections;
public class _MyMouseLook : MonoBehaviour {
GameObject myPlayer;
void Start()
{
myPlayer = this.transform.parent.gameObject; //Sets the myPlayer variable to the parent of the camera this script is attached to.
}
void Update()
{
var mouseY = new Vector2(Input.GetAxisRaw("Mouse Y"), 0);
var mouseX = new Vector2 (0, Input.GetAxisRaw ("Mouse X"));
myPlayer.transform.Rotate(mouseX);
transform.Rotate(-mouseY);
}
}
Every application of Mathf.clamp that I can think of or find an example of to stop the player from looking higher or lower than 90 degrees simply does nothing. I feel like I must be badly misunderstanding how Mathf.clamp works. Any suggestions?
Comment