I’ve been working on my own FPS controller and I am working on a flip mechanism (as in parkour). I am trying to get the camera to flip with the player, but I feel like my MouseLook script is messing it up and flipping the camera over once it reaches a certain angle.
var player : Transform;
var lookSensitivity : float = 5.0;//How sensitive the mouse is.
var lookSmoothDamp : float = 0.1;//This is used to smooth out the mouse looking.
var minXView : float = 80;//The angle that represents how low the camera can look on the x-axis.
var maxXView : float = 80;//The angle that represents how high the camera can look on the y-axis.
@HideInInspector
var currentAimRacio : float = 1;//Our aim ratio's current value. It has to be between 0 and 1.
@HideInInspector
var yRotation : float;//We can set the camera's y rotation to be equal to this float and we can make this float equal to a float returned from a smooth damp function. This allows for the camera to have smooth movement.
@HideInInspector
var xRotation : float;//We can set the camera's x rotation to be equal to this float and we can make this float equal to a float returned from a smooth damp function. This allows for the camera to have smooth movement.
@HideInInspector
var currentYRotation : float;//Our camera's current rotation on the Y axis.
@HideInInspector
var currentXRotation : float;//Our camera's current rotation on the X axis.
@HideInInspector
var yRotationV : float;//Mathf.SmoothDamp needs a variable for its velocity. We just have to supply it, the variable isn't given a default value.
@HideInInspector
var xRotationV : float;//Mathf.SmoothDamp needs a variable for its velocity. We just have to supply it, the variable isn't given a default value.
function Update ()
{
yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
xRotation = Mathf.Clamp(xRotation, -minXView, maxXView);
currentXRotation = Mathf.SmoothDamp(currentXRotation,xRotation,xRotationV,lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation,yRotation,yRotationV,lookSmoothDamp);
transform.rotation = Quaternion.Euler(player.localEulerAngles.x + currentXRotation, currentYRotation, player.localEulerAngles.z);
}