I am making a first person game, and currently I am working on being able to move around and view. To rotate the camera, i made a quaternion with either 5 more or less degrees on x or y. But when I run it, it just mvoes up and down quickly and rapidly. How can I look around with my mouse Smoothly?
Here is my code:
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
Transform tf;
void Start () {
tf = GetComponent<Transform>();
}
void Update () {
if(Input.GetAxis("Mouse X")<0){
Quaternion r = Quaternion.Euler(tf.rotation.x + 5,tf.rotation.y, tf.rotation.z);
tf.rotation = r;
}
if(Input.GetAxis("Mouse X")>0){
Quaternion r = Quaternion.Euler(tf.rotation.x - 5,tf.rotation.y, tf.rotation.z);
tf.rotation = r;
}
if(Input.GetAxis("Mouse Y")<0){
Quaternion r = Quaternion.Euler(tf.rotation.x,tf.rotation.y + 5, tf.rotation.z);
tf.rotation = r;
}
if(Input.GetAxis("Mouse Y")>0){
Quaternion r = Quaternion.Euler(tf.rotation.x,tf.rotation.y - 5, tf.rotation.z);
tf.rotation = r;
}
}
}