ppb / pursuedpybear

A python game engine.
https://ppb.dev/
Artistic License 2.0
259 stars 98 forks source link

KeyBoardMovementSprite moves too quickly when moving diagonally #709

Closed sheenarbw closed 3 months ago

sheenarbw commented 5 months ago

The new KeyBoardMovementSprite handles up, down, left and right movements fine, but if you move diagonally it moves much faster.

AstraLuma commented 3 months ago

Would you say approximately 40% faster?

Yup, looks like the code fell into one of the classic blunders: increased speed due to hypotenuse.

AstraLuma commented 3 months ago

ppb.features.default_sprites.KeyBoardMovementSprite does not normalize its direction vector before applying it to the movement equation.

There are methods in the Vector to perform this normalization.

AstraLuma commented 3 months ago

Also, keep in mind that the zero vector may explode in the math, so you may need to special case that.