mirror of
https://github.com/photonstorm/phaser
synced 2024-11-17 18:28:57 +00:00
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:
parent
78d1b75872
commit
e8f6bae7cb
1 changed files with 9 additions and 1 deletions
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue