Skip to content

Commit

Permalink
A Body with damping and drag enabled would fail to move if it wen…
Browse files Browse the repository at this point in the history
…t from zero velocity to a new velocity inside an `update` loop. It will now reset its speed accordingly and retain its new velocity
  • Loading branch information
photonstorm committed May 10, 2019
1 parent 78d1b75 commit e8f6bae
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/physics/arcade/World.js
Expand Up @@ -1190,8 +1190,11 @@ var World = new Class({
if (useDamping)
{
// Damping based deceleration

velocityX *= dragX;

speed = Math.sqrt(velocityX * velocityX + velocityY * velocityY);

if (FuzzyEqual(speed, 0, 0.001))
{
velocityX = 0;
Expand Down Expand Up @@ -1228,6 +1231,8 @@ var World = new Class({
// Damping based deceleration
velocityY *= dragY;

speed = Math.sqrt(velocityX * velocityX + velocityY * velocityY);

if (FuzzyEqual(speed, 0, 0.001))
{
velocityY = 0;
Expand Down Expand Up @@ -1258,10 +1263,13 @@ var World = new Class({

body.velocity.set(velocityX, velocityY);

if (maxSpeed > -1 && body.velocity.length() > maxSpeed)
if (maxSpeed > -1 && speed > maxSpeed)
{
body.velocity.normalize().scale(maxSpeed);
speed = maxSpeed;
}

body.speed = speed;
},

/**
Expand Down

0 comments on commit e8f6bae

Please sign in to comment.