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

Arcade Physics: maxSpeed not applied consistently #6329

Closed
Bambosh opened this issue Dec 24, 2022 · 1 comment · Fixed by #6330
Closed

Arcade Physics: maxSpeed not applied consistently #6329

Bambosh opened this issue Dec 24, 2022 · 1 comment · Fixed by #6330

Comments

@Bambosh
Copy link
Contributor

Bambosh commented Dec 24, 2022

Version

  • Phaser Version: v3.55.2
  • Operating system: Windows 11
  • Browser: All browsers

Description

When using the maxSpeed property with a given body in arcade physics, the expected behaviour is that the speed of that body will be capped on each physics update step. In practice, it appears that this only applies on every other step. As a result, arcade bodies with a maxSpeed value will end up moving slightly faster than they should.

Example Test Code

https://codesandbox.io/s/phaser-3-max-speed-issue-iu9beh

Additional Information

The cause of this behaviour appears to be in the 'computeVelocity' function. When deciding whether to scale the body's velocity, a comparison is made to confirm that speed > maxSpeed. At this point, speed has not actually been updated to represent the body's new velocity. As far as I can tell, changing this comparison to body.velocity.length() > maxSpeed should fix the undesired behaviour.

@photonstorm
Copy link
Collaborator

Thanks for opening this issue, and for submitting a PR to fix it. We have merged your PR into the master branch and attributed the work to you in the Change Log. If you need to tweak the code for whatever reason please submit a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants