- Home /
WHY My Camera twitch ?????
When I play my mouse look twitch . There is my MouseLook Script : using UnityEngine; using System.Collections;
/// Mouse Look
/// Version 0.03
[AddComponentMenu("Camera/MouseLook")]
public class My_MouseLook : MonoBehaviour {
[Header ("Transforms")]
public Transform Player;
public Transform Camera;
[Header ("Rotation")]
public float RotationByX = 0F ;
public float RotationByY = 0F ;
[Header ("Max And Min")]
public float MaximumByY = 75F ;
public float MinimumByY = 75F ;
[Header ("Sensitivity")]
public float SensitivityByX = 5F ;
public float SensitivityByY = 5F ;
[Header ("Smooth")]
public float SmoothTimeByX = 5F ;//
public float SmoothTimeByY = 5F ;//
private Quaternion PlayerRotation ;
private Quaternion CameraRotation ;
void Start ()
{
PlayerRotation = Player.localRotation;
CameraRotation = Camera.localRotation;
}
void Update ()
{
MouseLook ();
}
void MouseLook ()
{
RotationByX = Input.GetAxis ("Mouse Y") * SensitivityByY;
RotationByY = Input.GetAxis ("Mouse X") * SensitivityByX;
PlayerRotation *= Quaternion.Euler (0f, RotationByY, 0f);
CameraRotation *= Quaternion.Euler (-RotationByX, 0f, 0f);
CameraRotation = ClampRotationAroundXAxis (CameraRotation);
if (RotationByY!= 0F )
{
Player.localRotation = Quaternion.Slerp (Player.localRotation, PlayerRotation, SmoothTimeByX * Time.deltaTime);//
}
if (RotationByX!= 0F )
{
Camera.localRotation = Quaternion.Slerp (Camera.localRotation, CameraRotation, SmoothTimeByY * Time.deltaTime);//
}
}
Quaternion ClampRotationAroundXAxis(Quaternion q)
{
q.x /= q.w;
q.y /= q.w;
q.z /= q.w;
q.w = 1.0f;
float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan (q.x);
angleX = Mathf.Clamp (angleX, -MinimumByY, MaximumByY);
q.x = Mathf.Tan (0.5f * Mathf.Deg2Rad * angleX);
return q;
}
}
Comment
Your answer
Follow this Question
Related Questions
ThirdPersonShooter-Camera-Script Optimization 0 Answers
How to split one view frustum between multiple cameras? 2 Answers
Fix MoveCamera can see body 0 Answers