Camera movement problem
Here's a code for first person camera control. The problem is when I rotate left or right, more than 90 degrees, the camera goes rotating like my car's steering wheel when I spot a hooker. Help?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerLook : MonoBehaviour { Vector2 mouseLook; Vector2 smoothV; public float sensitivity = 5.0f; public float smoothing = 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;
mouseLook.y = Mathf.Clamp (mouseLook.y, -90f, 90f);
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612160753im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I make a Unreal Engine Example Project third preson player controller? 1 Answer
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
Connect controls to Camera angle 0 Answers
Xbox one controller spinning 0 Answers
Unity3D accelerometer camera rotation realistic controls 0 Answers