Scale damping

This commit is contained in:
samme 2020-10-19 19:14:09 -07:00
parent 165c9085e6
commit be558d2dca
2 changed files with 9 additions and 5 deletions

View file

@ -335,10 +335,11 @@ var Body = new Class({
/** /**
* When `useDamping` is false (the default), this is absolute loss of velocity due to movement, in pixels per second squared. * When `useDamping` is false (the default), this is absolute loss of velocity due to movement, in pixels per second squared.
* *
* When `useDamping` is true, this is 1 minus the damping factor. * When `useDamping` is true, this is a damping multiplier between 0 and 1.
* A value of 0 means the Body stops instantly.
* A value of 0.01 mean the Body loses 99% of its velocity per second.
* A value of 0.1 means the Body loses 90% of its velocity per second.
* A value of 1 means the Body loses no velocity. * A value of 1 means the Body loses no velocity.
* A value of 0.95 means the Body loses 5% of its velocity per step.
* A value of 0.5 means the Body loses 50% of its velocity per step.
* *
* The x and y components are applied separately. * The x and y components are applied separately.
* *
@ -486,8 +487,8 @@ var Body = new Class({
* by using damping, avoiding the axis-drift that is prone with linear deceleration. * by using damping, avoiding the axis-drift that is prone with linear deceleration.
* *
* If you enable this property then you should use far smaller `drag` values than with linear, as * If you enable this property then you should use far smaller `drag` values than with linear, as
* they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow * they are used as a multiplier on the velocity. Values such as 0.05 will give a nice slow
* deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. * deceleration.
* *
* @name Phaser.Physics.Arcade.Body#useDamping * @name Phaser.Physics.Arcade.Body#useDamping
* @type {boolean} * @type {boolean}

View file

@ -1248,6 +1248,7 @@ var World = new Class({
if (useDamping) if (useDamping)
{ {
// Damping based deceleration // Damping based deceleration
dragX = Math.pow(dragX, delta);
velocityX *= dragX; velocityX *= dragX;
@ -1287,6 +1288,8 @@ var World = new Class({
if (useDamping) if (useDamping)
{ {
// Damping based deceleration // Damping based deceleration
dragY = Math.pow(dragY, delta);
velocityY *= dragY; velocityY *= dragY;
speed = Math.sqrt(velocityX * velocityX + velocityY * velocityY); speed = Math.sqrt(velocityX * velocityX + velocityY * velocityY);