Mouse Input Causes Stuttering

MouseX = (Input.GetAxis("Mouse X") * MouseSensitivity) * Time.deltaTime;

When also moving causes other objects in my scene to be jittery and jump around

MouseX = (UnityEngine.Random.Range(5, 7) * Time.deltaTime);

(The random is there to simulate random mouse movements) Causes no lag whatsoever. Smooth as butter whenever I move. This is seriously pissing me off. I’ve had stutter issues since day 1 of starting unity, that for some reason, absolutely nobody else has. I’ve tried everything, including moving rotation code into lateupdate.

For the love of god can someone please help me figure this out. The only time that the mouse movement doesn’t stutter is if I smoothdamp it, but I’d rather not have to do that when the second line of code that I posted works fine. Absolutely no reason for this to be happening.

The code is taken completely out of context.
You’re taking the Mouse X movement multiplied by a sensitivity factor and then that value is multiplied by Time.deltaTime.
But what is your rotation code? Because this MouseX value is only a small value when the mouse moves.
when the mouse does not move it is 0. and 0 * 2 * Time.deltaTime is still 0

Could you please provide the actual Update method with the rotation code?

            LocalPlayerBody.transform.Rotate(Vector3.up * MouseX);

In update(). Only dealing with the X rotation for now.

Like I said, if I hardcode the X value (so the player spins endlessly), there’s no stutter. I’ve tried smoothdamp which seems to work, but I feel like I shouldn’t have to smoothdamp just to get a non jittery mouse look.

I also removed deltatime from the input. Nothing works.

If I take this simple script for example and put it on a 3D Cube it rotates smoothly as long as I move my mouse of course.
Even if I multiply the value by Time.deltaTime and increase the speed values (else it’ll rotate barely) it still rotates just fine.

float horizontalSpeed = 2.0f;
float verticalSpeed = 2.0f;

void Awake() => gameObject.name = "CubeA";

void Update()
{
    float h = horizontalSpeed * Input.GetAxis("Mouse X");
    float v = verticalSpeed * Input.GetAxis("Mouse Y");

    transform.Rotate(v, h, 0);
}

Put a camera on it and then move it, while also rotating it. It’s a first person controller.

https://images.squarespace-cdn.com/content/v1/525ed7ade4b0924d2f499223/1470768528312-LJ2FI7Z2MUSE738G71H5/ke17ZwdGBToddI8pDm48kElFfrMdeCrej--maRuyYEZZw-zPPgdn4jUwVcJE1ZvWEtT5uBSRWt4vQZAgTJucoTqqXjS3CfNDSuuf31e0tVGPaWGxiRs2iHF1HDQIXdQBehsJP1jD73N9m5CSjMxfaqEcAfnVBrEqrgp1UxUHGkY/image-asset.gif?format=500w

This gif ^ Is what im experiencing, just not AS bad. Completely unplayable though. I would like to know if I’m going to be forced to smoothdamp the mouse values. I would rather not, but that’s my last resort.

FYI I tried with a rigidbody, setting the velocity. The playerbody is parented to it, and rotates on its own. The camera is parented to the playerbody. Still lags.

I then removed the rigidbody and moved solely based on transform.translate. Still choppy when strafing around an object.

But then of course, when I manually set the X rotation value, I get absolutely no choppiness. This is so dumb.

Can this get raised to the actual unity support team? There’s countless numbers of threads with this exact issue and nobody has solved it. I’ve been through 60+ pages of google searches and nobody has an answer. For the love of god please someone help me fix this.

My character controller goes like this

Empty Gameobject (with rigidbody) moves with .velocity (does not rotate on any axis)
Cylinder (can rotate on X axis)
Camera (can rotate on Y axis)

Whenever I strafe around an object (walk and rotate camera) everything in the scene jitters. I have interpolation enabled on the rigidbody. If lerping/smoothdamp is the only way to prevent this stutter, please let me know, because this is driving me insane.

Ah, I thought you meant only the rotation of the object. Not in combination with a camera attached.

Well that looks like a bug to me as it is even in their Standard Assets. I looked up the FirstPersonController with a RigidBody.

If you want attention from the unity support, I’d suggest reporting it as a bug.
Easiest is to submit your own micro reproduction project.
Or you could create a new bug reproduction project in 2020.2 with only the Standard Assets of 2018.4. (removing a few lines about GUIText that is obsolete else it won’t compile in 2019.4 or 2020.2). Save the Sample Scene with a RigidBodyFPSController and some environment setup.

That should do. I could report the bug for you if you’d like but then responses will be going through my email until they create an issue tracker for it.

If you encounter bugs, bug reports are always the way to go if you want unity’s support.

Please do report the bug, that would mean the world to me. It baffles me though, since unity has been out over a decade and this extremely simple bug still persists. You would have thought that their engineers would have taken care of it by now.

yeah well sometimes it slips through and gets backported to other versions even.
thoughout all the years that I’ve used Unity, lots of things baffled me. But all we can do as community is to report the bugs so that they can take a look at it and decide what to do with it.

I’ve reported the bug and will edit the post with the case number.
Once an issue tracker is active I’ll place the link as well. But I don’t know if they’re going to be active around christmas.

Edit: case 1300361

This still bothers me though considering there’s triple A games like rust and tarkov that are first person shooters and do not seem to suffer from this bug.

They might have different implementations or worked around it. Maybe they’re using Cinemachine and don’t experience this bug that way.

I haven’t made a third person or first person controller in a while since I’m working on VR projects.

Not sure if it’s the actual cause of the issue… but You shouldn’t be multiplying mouse movement by Time.deltaTime since the movement increases with ‘time’ so time is already accounted for.

1 Like

I used the Brackey’s look script, it was jittery when looking around, I fixed it by tagging the camera as Main Camera, it worked idk

I’m having the same problem and I don’t understand what you mean by “Set the X Rotation value”
| |
here’s part of my script V V

transform.Rotate(Vector3.up * Input.GetAxisRaw(“Mouse X”) * mouseSensitivity * Time.deltaTime);

verticalLookRotation += Input.GetAxisRaw(“Mouse Y”) * mouseSensitivity * Time.deltaTime;
verticalLookRotation = Mathf.Clamp(verticalLookRotation, -65, 50);

cameraHolder.transform.localEulerAngles = Vector3.left * verticalLookRotation;

If I need to change my script let me know

Probably not. Please don’t necro-post. If you have a new question, make a new post. It’s FREE!!

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
    - links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

  • Do not TALK about code without posting it.
    - Do NOT post unformatted code.
  • Do NOT retype code. Use copy/paste properly using code tags.
  • Do NOT post screenshots of code.
  • Do NOT post photographs of code.
  • Do NOT attach entire scripts to your post.
  • ONLY post the relevant code, and then refer to it in your discussion.

If you need more information about what your program is doing as well as how and where it is deviating from your expectations, that means it is…

Time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Here is how you can begin your exciting new debugging adventures:

You must find a way to get the information you need in order to reason about what the problem is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the names of the GameObjects or Components involved?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as Debug.Log("Problem!",this);

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer for iOS: https://discussions.unity.com/t/700551 or this answer for Android: https://discussions.unity.com/t/699654

If you are working in VR, it might be useful to make your on onscreen log output, or integrate one from the asset store, so you can see what is happening as you operate your software.

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

If your problem is with OnCollision-type functions, print the name of what is passed in!

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494

If you are looking for how to attach an actual debugger to Unity: https://docs.unity3d.com/2021.1/Documentation/Manual/ManagedCodeDebugging.html

“When in doubt, print it out!™” - Kurt Dekker (and many others)

Note: the print() function is an alias for Debug.Log() provided by the MonoBehaviour class.