Skip to content

Commit 579c6ba

Browse files
committed
Body.useDamping is a new boolean property that allows you to use a damping effect for drag, rather than the default linear deceleration.
1 parent 9aa80b2 commit 579c6ba

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/physics/arcade/Body.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ var Body = new Class({
411411
this.onOverlap = false;
412412

413413
/**
414-
* The Body's absolute maximum velocity, in pixels per second.
414+
* The Body's absolute maximum velocity.
415+
*
415416
* This limits the Body's rate of movement but not its `velocity` values (which can still exceed `maxVelocity`).
416417
*
417418
* @name Phaser.Physics.Arcade.Body#maxVelocity
@@ -430,6 +431,24 @@ var Body = new Class({
430431
*/
431432
this.friction = new Vector2(1, 0);
432433

434+
/**
435+
* If this Body is using `drag` for deceleration this property controls how the drag is applied.
436+
* If set to `true` drag will use a damping effect rather than a linear approach. If you are
437+
* creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in
438+
* the game Asteroids) then you will get a far smoother and more visually correct deceleration
439+
* by using damping, avoiding the axis-drift that is prone with linear deceleration.
440+
*
441+
* If you enable this property then you should use far smaller `drag` values with linear, as
442+
* they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow
443+
* deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately.
444+
*
445+
* @name Phaser.Physics.Arcade.Body#useDamping
446+
* @type {boolean}
447+
* @default false
448+
* @since 3.10.0
449+
*/
450+
this.useDamping = false;
451+
433452
/**
434453
* The rate of change of this Body's rotation, in degrees per second.
435454
*

src/physics/arcade/components/Drag.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ var Drag = {
6161
{
6262
this.body.drag.y = value;
6363

64+
return this;
65+
},
66+
67+
/**
68+
* [description]
69+
*
70+
* @method Phaser.Physics.Arcade.Components.Drag#setDamping
71+
* @since 3.10.0
72+
*
73+
* @param {boolean} value - `true` to use damping for deceleration, or `false` to use linear deceleration.
74+
*
75+
* @return {this} This Game Object.
76+
*/
77+
setDamping: function (value)
78+
{
79+
this.body.useDamping = value;
80+
6481
return this;
6582
}
6683

0 commit comments

Comments
 (0)