- Home /
I have a laggy camera, how do i fix it
I have a problem with my camera. Since i linked it to the upper bosy rotating its just a little laggy, it doesnt fill so smooth as before. One extra question for some reason when i start unity the camera(upperBody) starts facing upwards probably beacuse of clamp but it shouldnt.Also I imported a soldier model from blender with bones, if that helps. I will be happy for any kind of help.
public class playerLook : MonoBehaviour { public float mouseSensitivity;
public Transform playerBody;
public Transform upperPlayerBody;
float xRotation;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, 30f, 120f);
upperPlayerBody.transform.localEulerAngles = new Vector3(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
upperPlayerBody.Rotate(Vector3.right * mouseY);
}
}
Answer by StringAtlas · Dec 11, 2020 at 04:09 AM
I'm not sure if this is the problem, but you can try:
upperPlayerBody.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
on line 19.
@StringAtlas I have no words. Thanks for help. Stay safe :D
Answer by Firestream1014 · Dec 13, 2020 at 12:09 AM
It seems that StringAtlas has helped in which case please mark this question as answered, otherwise... Rather than applying these movements in update, do it in LateUpdate.
Your answer