# \[ARCADE physics\] Incorrect velocity vector when trying to fly forward

**URL:** <https://phaser.discourse.group/t/arcade-physics-incorrect-velocity-vector-when-trying-to-fly-forward/4126>\
**Category:** Phaser 3\
**Created:** [November 2, 2019, 1:56pm UTC](https://phaser.discourse.group/t/arcade-physics-incorrect-velocity-vector-when-trying-to-fly-forward/4126 "2019-11-02T13:56:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NickRimer](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nickrimer/32/2254_2.png) [@NickRimer](https://phaser.discourse.group/u/NickRimer)\
**Post date:** [November 2, 2019, 1:56pm UTC](https://phaser.discourse.group/t/arcade-physics-incorrect-velocity-vector-when-trying-to-fly-forward/4126/1 "2019-11-02T13:56:32Z")

</div>

Hello there!  
I’m working with this example (asteroids movement): [LINK](http://labs.phaser.io/edit.html?src=src%5Cphysics%5Carcade%5Cspace.js)

There is a strange behaviour that blows my brain out. It can be better seen on the attached video.  
All I’ve done was a small rotation and then just pressed UP cursor key.

[VIDEO](https://www.html5gamedevs.com/uploads/monthly_2019_11/1226550856_2019-11-0112-02-08.mp4.72d23b497f1a64aab2b48b571b9fe469.mp4)

As you can see (with the help of turned on debugger) velocity vector moves (rotates) during fly until it reaches bottom-right corner of the bounding box. Also it force ship to fly wrong, it can be noticed even without debugger. Expected that velocity vector to be applied directly to where ship’s nose is (or more correctly, ship have to move to the opposite side the engines work vector; see the picture).

![123](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/1/10c74815ca588b5d1061697ef00fe7795c5d4f4b.png)

What can be the solution of this problem? Seems **velocityFromRotation()** function works not as expected. Or there is something been lost.

Best regards,  
Nick Rimer

---

<div class="post-metadata">

**Author:** ![Telinc1](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/telinc1/32/60_2.png) [@Telinc1](https://phaser.discourse.group/u/Telinc1)\
**Post date:** [November 2, 2019, 2:32pm UTC](https://phaser.discourse.group/t/arcade-physics-incorrect-velocity-vector-when-trying-to-fly-forward/4126/2 "2019-11-02T14:32:33Z")

</div>

The example uses `setMaxVelocity` to limit the ship’s speed (this is around line 175). [The two axes of the velocity are calculated separately](https://github.com/photonstorm/phaser/blob/v3.20.1/src/physics/arcade/World.js#L1299). So, when moving at an angle, one axis of the velocity will increase faster than the other and it will stop increasing when it hits the max value. The slower axis will keep changing independently until both axes are equal. This explains why the ship changes direction while moving. You can fix it by using `ship.body.setMaxSpeed` instead of `ship.setMaxVelocity`; when the speed is limited, the entire velocity vector is scaled, not its individual components.

Even so, the same problem will occur when decelerating because drag is also applied separately by default. You can fix this by making the body use damping instead of linear drag: `ship.body.useDamping = true;` You would also need to tweak the drag; [as the docs say, albeit a little indirectly](https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Body.html#useDamping__anchor), it should be a number less than 1 when using damping.

All of that said, I’m not sure why the example misuses all of these features. It took me a while to figure out why the velocity drifts like that, but the docs outright tell you that damping should be used if your angles change freely.

---

<div class="post-metadata">

**Author:** ![NickRimer](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nickrimer/32/2254_2.png) [@NickRimer](https://phaser.discourse.group/u/NickRimer)\
**Post date:** [November 7, 2019, 9:24am UTC](https://phaser.discourse.group/t/arcade-physics-incorrect-velocity-vector-when-trying-to-fly-forward/4126/3 "2019-11-07T09:24:29Z")

</div>

Whoa! Thank a lot, man. Your answer forced it to work good for now!

And a bit offtopic. Can you recommend something good material to well understand what is what in Phaser? Seems reading the whole documentation up to down is not a good idea. Really wanna understand _how to understand what methods or properties to use in what kind of situation/mechanics_.

Best regrads,  
Nick Rimer
