- Home /
Player moving faster when maximized game view
Hey guys, every time when my game view is maximized, the player moves a lot faster, as when the game view is not maximized. Does someone know how to fix that?
Here's my movement code (it's on void Update):
//Movement
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
velocity.y += gravity * Time.fixedDeltaTime;
controller.Move(move * speed * Time.fixedDeltaTime);
controller.Move(velocity * Time.fixedDeltaTime);
Answer by rh_galaxy · Mar 23 at 03:51 PM
If you move it to FixedUpdate() it should work better. The reason for this is probably that the framerate is lower when you maximize the window, so Update() runs less often. But you still use Time.fixedDeltaTime which is constant (20 ms probably). Otherwise you can change Time.fixedDeltaTime to Time.deltaTime and keep it in Update().
Update: Why you would want to do physics in FixedUpdate() and not in Update(): With fixedDeltaTime timing is constant, and if you run the game on different computers with different frame rate the game objects would behave slightly different if you do it with deltaTime. That is reason enough, but what if you would like to record and replay a sequence? Or if you want to make the game multiplayer over Internet...
Answer by antonsimmerle · Mar 23 at 04:06 PM
Thanks for the reply! When I change Update to FixedUpdate the Scene stuttering.
I'm not sure, but try changing the Rigidbody component to interpolate. You can also set the Fixed Timestep (Project Settings->Time) to for example 0.01 S (100 Hz) instead of the default 50 Hz. And you should read this: https://www.unity3dtips.com/unity-fix-movement-stutter/
There also exist youtube tutorials on this subject.