-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Arcade Physics: maxSpeed not applied consistently #6329
Description
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.