- Home /
Is there any reason VSync should effect the charactercontroller?
Hey so today I set up an options menu where the player could select from any of the six Quality Settings Levels (Edit -> Project Settings -> Quality). By default, the levels Fastest, Fast, and Simple have V Sync Count set to 'Don't Sync'. I ran the game, and initially everything seemed fine. But then I noticed in the Fastest, Fast, and Simple quality levels, that my CharacterController began to malfunction.
For whatever reason, the character would temporarily get stuck in the air after a jump, or stuck just above the ground. I also noticed that, while in those same quality levels, my video card (GTX970) would start to make some high pitched whiny noises.
So I looked at the different options in the quality levels and found that the difference between the quality settings where the controller was bugging out and the ones where he wasn't were the ones where V Sync Count was set to 'Don't Sync'. I set the VSync of the lower quality levels to 'Every Second VBlank' and now the controller is working as it should.
I have no idea how or why VSync should effect the character controller but would be extremely grateful if someone could enlighten me.
Edit: Here is a video of the issue. In the first half, I show normal character behavior while the game is on quality level 'Fantastic'. In the second half, i set the quality level to 'Fastest' (Vsync off) and you can see that I can't even get my character off the ground.
I also discovered that providing horizontal or vertical input nullifies the problem, but when their is no input, gravity magically shuts off and I get stuck in the air or on the ground until I provide h or v input.
Answer by GameDev_Chuck · Oct 12, 2016 at 07:35 AM
Okay so I believe the issue has been resolved. What was happening was that because I was running the lowest settings on my moderately powerful pc, Update was being called so frequently that time.deltatime became an unusable small number (if it was even greater than 0) and therefore wasn't effecting any values it was being multiplied with/divided by (in this case, gravity). I was able to correct this issue by setting a target frame rate when setting the player settings to anything that had vsync turned off.
Thank you for this insight! I was breaking my head against the walls for two days becouse of this problem. $$anonymous$$y character controller wasn't moving in build (with vsync off), and now I understand why. Setting target frame rate to 60 at the awake of the game seems to have solved this (at least for now).
No problem, glad I was able to help. To expand upon my answer, the Vector3 class uses floats for x, y and z. The precision/approximate range of a float is -3.4 × 10^38to +3.4 × 10^38 or 7 digits.
I don't know for sure, but I'm guessing that if your Time.deltatime is low enough, and your vertical velocity and/or gravity are low enough, that the y value of your movement vector is getting truncated to 0. This results in your player getting stuck in the air at the top of his jump rather than beginning descent.
Answer by Arcana96 · Oct 12, 2016 at 01:28 AM
Try moving the movement of your camera into LateUpdate() it sounds as if your camera is trying to play catchup with your player movements because of the VSync.
Thanks, but that's not it. $$anonymous$$y camera code is already in LateUpdate. I created a quick video of the problem where you can see that the bug has nothing to do with the camera. First half of the video is how the game runs normally, while in quality level 'Fantastic', and the second half shows the bug while in 'Fastest' quality setting with Vsync off.
I also discovered that providing horizontal or vertical input effects the issue. If there is no h or v input then I can't even jump off the ground. Or, if I get stuck in the air, the only way to get down is to tap h or v, at which point gravity magically turns back on. Still pretty damn confused over here