I have a camera that rotates on the Mouse X axis however for some reason it continues to rotate slightly even when the mouse isn’t moving, the camera is attached to a capsule object as part of a third person camera. here is the code for the camera and the capsule (controller).
the controller script
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float movementSpeed = 10;
public float turningSpeed = 60;
public float jumpForce = 800;
public Transform cameraObj;
private Rigidbody rb;
private bool canJump;
void Awake()
{
rb = gameObject.GetComponent<Rigidbody> ();
}
void Update()
{
float horizontal = cameraObj.rotation.y;
transform.Rotate (0, horizontal, 0);
float vertical = Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime;
transform.Translate (0, 0, vertical);
float strafe = Input.GetAxis("Horizontal") * movementSpeed * Time.deltaTime;
transform.Translate(strafe, 0, 0);
if (Input.GetButtonDown ("Jump") == true)
{
if (canJump == true)
{
rb.AddForce (0,jumpForce,0);
canJump = false;
}
}
}
}
The camera script
using UnityEngine;
using System.Collections;
public class ThirdPersonCamera : MonoBehaviour {
public GameObject target;
public float rotateSpeed = 5;
private Vector3 offset;
void Awake()
{
offset = target.transform.position - transform.position;
}
void LateUpdate()
{
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
float vertical = Input.GetAxis("Mouse Y") * rotateSpeed;
target.transform.Rotate(vertical, horizontal, 0);
float desiredAngle_X = target.transform.eulerAngles.x;
float desiredAngle_Y = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(desiredAngle_X, desiredAngle_Y, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt (target.transform);
}
}
How do I stop the camera from moving even when the mouse is still?