Hi there, so i have a script for camera movement/control and it was giving me issues related to a clamp it was going beyond the boundaries and returning to the position instead of just clamp, so i decided to do a new script more simple, and it’s doing the same.
Previous problem: The other script which is more advanced and better done have those problems too.
Problem: If you use this script in a camera and move fast the mouse to down or up it will go beyond the clamp and then return to the clamp.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MouseLook2 : MonoBehaviour{
Vector2 mouseDelta;
Vector3 absolutePosition;
Vector3 finalRotation;
Vector3 smoothedPosition;
public Vector2 yLimit = new Vector2(-75,150);
public Vector2 sensitivity = new Vector2(2, 2);
public GameObject characterBody;
public void LateUpdate(){
mouseDelta = new Vector2 (Input.GetAxisRaw ("Mouse X"), Input.GetAxisRaw ("Mouse Y"));
//Add inverted mouse delta value of Y (If we want inverted view just delete the negative sign)
absolutePosition.x = -mouseDelta.y;
//Add Mouse delta value of X
absolutePosition.y = mouseDelta.x;
finalRotation = absolutePosition;
finalRotation = new Vector3(Mathf.Clamp(finalRotation.x,-yLimit.y,-yLimit.x),0,0);
transform.localEulerAngles += finalRotation;
}
}
Thanks in advanced.