I'm using pointer locking for a 2D game (where you perform calculations based on the delta in mouse positions from frame to frame). I'm having some basic math/logic issues with accomplishing what I want.
I'd like the player to be able to send the character in the direction they last moved their mouse (so if they stop moving the mouse, the character continues to travel in the direction they last moved in).
The issue I'm experiencing is the movementx and movementy values are integers. If the player moves the mouse quickly so that from one mousemove event to the next many pixels are traversed, the direction to move the character is reasonably precise. Every other scenario results in the last movement having movementx or movementy only being -1/0/+1. If the character only moves based on the last movement of the mouse, it very often only moves in one of 8 directions.
How can I be more precise than 8 directions even on slow/short mouse movements while ensuring the last bit of movement of the mouse is always what's being used?
My first thought was to average out the last n movement values, but that can easily result in the character not always moving in the direction the mouse moved last. I've not really had too many other thoughts though, so I came here for assistance.