From 579c6ba6074d6b275c26749f4d54b1e073d2c33c Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sun, 3 Jun 2018 17:08:08 +0100 Subject: [PATCH] Body.useDamping is a new boolean property that allows you to use a damping effect for drag, rather than the default linear deceleration. --- src/physics/arcade/Body.js | 21 ++++++++++++++++++++- src/physics/arcade/components/Drag.js | 17 +++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index 774feaa60..acc516e57 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -411,7 +411,8 @@ var Body = new Class({ this.onOverlap = false; /** - * The Body's absolute maximum velocity, in pixels per second. + * The Body's absolute maximum velocity. + * * This limits the Body's rate of movement but not its `velocity` values (which can still exceed `maxVelocity`). * * @name Phaser.Physics.Arcade.Body#maxVelocity @@ -430,6 +431,24 @@ var Body = new Class({ */ this.friction = new Vector2(1, 0); + /** + * If this Body is using `drag` for deceleration this property controls how the drag is applied. + * If set to `true` drag will use a damping effect rather than a linear approach. If you are + * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in + * the game Asteroids) then you will get a far smoother and more visually correct 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 with linear, as + * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow + * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. + * + * @name Phaser.Physics.Arcade.Body#useDamping + * @type {boolean} + * @default false + * @since 3.10.0 + */ + this.useDamping = false; + /** * The rate of change of this Body's rotation, in degrees per second. * diff --git a/src/physics/arcade/components/Drag.js b/src/physics/arcade/components/Drag.js index 2bda340e8..2e527cfe2 100644 --- a/src/physics/arcade/components/Drag.js +++ b/src/physics/arcade/components/Drag.js @@ -61,6 +61,23 @@ var Drag = { { this.body.drag.y = value; + return this; + }, + + /** + * [description] + * + * @method Phaser.Physics.Arcade.Components.Drag#setDamping + * @since 3.10.0 + * + * @param {boolean} value - `true` to use damping for deceleration, or `false` to use linear deceleration. + * + * @return {this} This Game Object. + */ + setDamping: function (value) + { + this.body.useDamping = value; + return this; }