Skip to content

Commit 675e433

Browse files
committed
Physics.Arcade.Body.setDamping is a new method that allows you to set the useDamping property of a Body in a chainable way. Fix phaserjs#5352
1 parent 7a849e2 commit 675e433

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,31 @@ var Body = new Class({
20722072
return this;
20732073
},
20742074

2075+
/**
2076+
* If this Body is using `drag` for deceleration this property controls how the drag is applied.
2077+
* If set to `true` drag will use a damping effect rather than a linear approach. If you are
2078+
* creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in
2079+
* the game Asteroids) then you will get a far smoother and more visually correct deceleration
2080+
* by using damping, avoiding the axis-drift that is prone with linear deceleration.
2081+
*
2082+
* If you enable this property then you should use far smaller `drag` values than with linear, as
2083+
* they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow
2084+
* deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately.
2085+
*
2086+
* @method Phaser.Physics.Arcade.Body#setDamping
2087+
* @since 3.50.0
2088+
*
2089+
* @param {boolean} value - `true` to use damping, or `false` to use drag.
2090+
*
2091+
* @return {Phaser.Physics.Arcade.Body} This Body object.
2092+
*/
2093+
setDamping: function (value)
2094+
{
2095+
this.useDamping = value;
2096+
2097+
return this;
2098+
},
2099+
20752100
/**
20762101
* Sets the Body's horizontal drag.
20772102
*

0 commit comments

Comments
 (0)