Skip to content

Commit 4bdb0de

Browse files
committed
The Arcade Physics Body.speed property is now set whenever you set the velocity via setVelocity or setVelocityX or setVelocityY which stops the body velocity being reset to zero if useDamping is enabled. Fix phaserjs#3888
1 parent fe2ddcf commit 4bdb0de

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Setting the `resolution` property in the Game Config to a value other than 1 wou
179179
* Matter.js has received a tiny update that prevents `collisionEnd` from triggering many times when it should only trigger once (thanks @mikewesthad)
180180
* Graphics objects couldn't be set to be ignored by Cameras. Now every renderable Game Object can be ignored by a Camera, either directly or via a Container. The exception are Groups because they don't render and are non-exclusive parents.
181181
* The Tilemap Culling function now uses the Tilemap tile dimensions for its bounds calculations, instead of the layer tile sizes, as they two don't have to match and it's the underlying grid size that takes precedence when calculating visible tiles. Fix #3893 (thanks @Zax37)
182+
* The Arcade Physics `Body.speed` property is now set whenever you set the velocity via `setVelocity` or `setVelocityX` or `setVelocityY` which stops the body velocity being reset to zero if `useDamping` is enabled. Fix #3888 (thanks @samme)
182183

183184
### Examples, Documentation and TypeScript
184185

src/physics/arcade/Body.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,8 @@ var Body = new Class({
14551455
{
14561456
this.velocity.set(x, y);
14571457

1458+
this.speed = Math.sqrt(x * x + y * y);
1459+
14581460
return this;
14591461
},
14601462

@@ -1472,6 +1474,11 @@ var Body = new Class({
14721474
{
14731475
this.velocity.x = value;
14741476

1477+
var vx = value;
1478+
var vy = this.velocity.y;
1479+
1480+
this.speed = Math.sqrt(vx * vx + vy * vy);
1481+
14751482
return this;
14761483
},
14771484

@@ -1489,6 +1496,11 @@ var Body = new Class({
14891496
{
14901497
this.velocity.y = value;
14911498

1499+
var vx = this.velocity.x;
1500+
var vy = value;
1501+
1502+
this.speed = Math.sqrt(vx * vx + vy * vy);
1503+
14921504
return this;
14931505
},
14941506

src/physics/arcade/components/Velocity.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var Velocity = {
2525
*/
2626
setVelocity: function (x, y)
2727
{
28-
this.body.velocity.set(x, y);
28+
this.body.setVelocity(x, y);
2929

3030
return this;
3131
},
@@ -42,7 +42,7 @@ var Velocity = {
4242
*/
4343
setVelocityX: function (x)
4444
{
45-
this.body.velocity.x = x;
45+
this.body.setVelocityX(x);
4646

4747
return this;
4848
},
@@ -59,7 +59,7 @@ var Velocity = {
5959
*/
6060
setVelocityY: function (y)
6161
{
62-
this.body.velocity.y = y;
62+
this.body.setVelocityY(y);
6363

6464
return this;
6565
},

0 commit comments

Comments
 (0)