- Home /
Fps Camera rotation very choppy and jittery
I'm extremely new to unity, and I'm trying to make a simple character controller with a rigidbody, but my camera movement is so extremely laggy.
void Look()
{
//Gets the mouse input and multiplies it by the sensitivity
float horizontal = Input.GetAxis("Mouse X") * sensitivity;
float vertical = Input.GetAxis("Mouse Y") * sensitivity;
//Variable which keeps track of the rotation of the camera on the y
yClamp += vertical;
//Rotates the camera and player
camera.transform.Rotate(-Vector3.right * vertical);
transform.Rotate(Vector3.up * horizontal);
//Prevents the camera from rotating upside down
if(yClamp >= 90)
{
Clamp(camera.transform, 270, "x");
vertical = 0;
yClamp = 90;
}
else if (yClamp <= -90)
{
Clamp(camera.transform, 90, "x");
vertical = 0;
yClamp = -90;
}
}
//Clamps the rotation of a given transform on the given axis by the given number
void Clamp(Transform obj, float value, string axis)
{
Vector3 eulerAngles = obj.eulerAngles;
switch (axis)
{
case "x":
eulerAngles.x = value;
break;
case "y":
eulerAngles.y = value;
break;
}
obj.eulerAngles = eulerAngles;
}
Any help is appreciated, thanks in advance.
Do you use call Look()? In update or FixedUpdate. Do you get stutter when you move character and mouse in the same time?
Answer by RendrWyre · Jan 05, 2020 at 06:38 PM
Updating camera movement should be done in LateUpdate().
https://docs.unity3d.com/ScriptReference/MonoBehaviour.LateUpdate.html
"LateUpdate is called after all Update functions have been called. This is useful to order script execution. For example a follow camera should always be implemented in LateUpdate because it tracks objects that might have moved inside Update."
I tried your solution, but sadly the problem persits. Thanks anyway!
"I've been testing some stuff and I've come to the conclusion that it's not about the script, but a problem with unity"
There's no issue with Unity and if you are using LateUpdate() for the camera then the issue is somewhere else. You don't have your camera as a child of the player, for example? that would cause issues. or, if you are trying to use the HDRP with a low/mid range rig you will also have issues. (even in a blank scene). Have you tried downloading the Standard Assets from the asset store and testing the default player controller to see if it still lags?
Srry :P I'm kinda new so I have no clue how unity works. I'll repost the code
Answer by tashfiq103 · Jan 08, 2020 at 01:11 AM
Hey, would you mind sharing the code that you used to rotate the camera for your game? :)
Your answer
Follow this Question
Related Questions
Stutter / Glitchy running character 1 Answer
m_MouseLook.LookRotation After Quaternion.LookRotation on some object 1 Answer
Dude, where's my scene? 2 Answers
Lock Character to Z axis. 1 Answer
character is moving forward on its own 0 Answers