Skip to content

Arcade Physics: maxSpeed not applied consistently #6329

@Bambosh

Description

@Bambosh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions