- Home /
Camera Shaking While Moving Or Looking Around
Hey guys . I'm using a FPS Controller in my game. So the hand and guns of my player shakes when my player moves or look around. And probably it's due to camera because camera shake cause hands and guns to shake.
This is the camera look script. Maybe the problem is in this script :
***using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseLook : MonoBehaviour { [SerializeField] private Transform PlayerRoot , LookRoot; [SerializeField] private bool invert; [SerializeField] private bool canUnlock = true; [SerializeField] private float sensivity = 5f; [SerializeField] private int smoothStep = 10; [SerializeField] private float smoothWeight = 0.4f; [SerializeField] private float rollAngle = 10f; [SerializeField] private float rollspeed = 3f; [SerializeField] private Vector2 default_look_limits = new Vector2 (-70f,80f);
private Vector2 lookAngels;
private Vector2 CurrentMouseLook;
private Vector2 smoothMove;
private float CurrentRoleAngel;
private int LastLookFrame;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
LockAndUnlockCursor();
if(Cursor.lockState == CursorLockMode.Locked)
{
LookAround();
}
}
void LockAndUnlockCursor()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
//if(Cursor.lockState == CursorLockMode.Locked)
//{
Cursor.lockState = CursorLockMode.None;
//}
/*else
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}*/
}
}
public void LookAround()
{
CurrentMouseLook = new Vector2(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"));
lookAngels.x += CurrentMouseLook.x * sensivity * (invert ? 1f : -1f);
lookAngels.y += CurrentMouseLook.y *sensivity;
lookAngels.x = Mathf.Clamp(lookAngels.x,default_look_limits.x,default_look_limits.y);
CurrentRoleAngel = Mathf.Lerp(CurrentRoleAngel,Input.GetAxisRaw("Mouse X") * rollAngle , Time.deltaTime * rollspeed );
LookRoot.localRotation = Quaternion .Euler(lookAngels.x , 0f, CurrentRoleAngel);
PlayerRoot.localRotation = Quaternion.Euler(0f,lookAngels.y , 0f);
}
}***