A Body with damping and drag enabled would fail to move if it went from zero velocity to a new velocity inside an update loop. It will now reset its speed accordingly and retain its new velocity

This commit is contained in:
Richard Davey 2019-05-10 12:28:06 +01:00
parent 78d1b75872
commit e8f6bae7cb

View file

@ -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;
@ -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;
@ -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;
},
/**