Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyBoardMovementSprite moves too quickly when moving diagonally #709

Closed
sheenarbw opened this issue Apr 8, 2024 · 3 comments · Fixed by #712
Closed

KeyBoardMovementSprite moves too quickly when moving diagonally #709

sheenarbw opened this issue Apr 8, 2024 · 3 comments · Fixed by #712
Labels
bug new contributor Apply to issues we think can be tackled by people new to PPB

Comments

@sheenarbw
Copy link
Contributor

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

@AstraLuma
Copy link
Member

Would you say approximately 40% faster?

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

@AstraLuma AstraLuma added bug new contributor Apply to issues we think can be tackled by people new to PPB labels May 20, 2024
@AstraLuma
Copy link
Member

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
Copy link
Member

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

jepler added a commit to jepler/pursuedpybear that referenced this issue May 20, 2024
Note that `scale_to` gracefully handles the zero vector, so no special
case is needed.

Jamie and I discussed and both had the gut feeling that leaving the
`direction` property unchanged from now (so that its elements are still
always +1, -1, or 0) was easier for implementation but could also make
sense when explained.

Closes: ppb#709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug new contributor Apply to issues we think can be tackled by people new to PPB
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants