- Home /
Question by
Cinhil124a · Feb 26, 2018 at 03:19 AM ·
c#scripting problemcamera-movementcamera rotatecamera-look
Confining Mouse Look on X axis
I want to stop my camera from rotating around the x axis past my feet and not past a certain hight. Basically 45/-45
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CamMouseLook : MonoBehaviour {
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
GameObject character;
void Start ()
{
character = this.transform.parent.gameObject;
}
void Update ()
{
var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
}
}
I did see the one other topic but it uses LocalEulerAngles and a clamp rotation which didn't feel right.
Small thing bugging me but got plenty of other places to work on,
Thanks guys/gals!
Comment
Your answer
Follow this Question
Related Questions
Free camera look question 2 Answers
How to make my Camera Controller look at target 0 Answers
Updating PC Control code for mouse camera movement Doesn't work Help! 0 Answers
Rotating and Translating a GameObject in relation to an AR Camera in Unity/Vueforia 0 Answers
How do I get my forward movement to match with the direction of my camera? 1 Answer