fogleman / Minecraft

Simple Minecraft-inspired program using Python and Pyglet
MIT License
5.21k stars 1.23k forks source link

Fixed jitter while walking and rotating at the same time. #128

Open mmhanson opened 3 years ago

mmhanson commented 3 years ago

Bug Description

The blocks on screen jitter when the player walks horizontally and rotates simultaneously.

Bug Reproduction

Walk to the side and rotate the camera at the same time.

Bug Cause

The bug is caused by a lack of synchronization between the on_mouse_update method, which updates the player rotation, and the update method, which updates the player position.

Bug Fix

In the on_mouse_update method of the Window class, instead of immediately updating the player rotation, buffer the updates. Then, in the update method of the same class, update the player position and player rotation at the same time.

Aareon commented 2 years ago

Tested and jitter is removed, but it appears this math is quite a bit more expensive now. I had consistently >60fps prior to testing, and have seen dips to ~28fps with the update on my, truthfully, borderline antiquated hardware.