Jump to content

maxVelocity with acceleration oddity


Recommended Posts

I have a problem when hitting maxVelocity with acceleration. It seems that the magnitude (or length) of a vector (Point) is not checked correctly when using acceleration and hitting maxSpeed.

This is really noticeable when setting to rotation to -3.82 and setting the acceleration value until maxVelocity is hit, the sprite will not travel in a straight line and skews by a positive y value even though the rotation has not changed.


[edit] Ok well I whipped up a quick demo in jsFiddle:  http://jsfiddle.net/TPTun/embedded/result/


In my own vector math I capped the velocity by checking the maxSpeed against the length of a vector (magnitude of a Point in Phasers case).

Is this a known issue? Am I assuming something I shouldn't be? I'm fairly new to vector math so I calculations may be wrong, let me know. 


Current I am getting around this by using this code below, and I can create a jsFiddle if you want a better demonstration.

if(this.body.velocity.getMagnitude() < this.maxSpeed){	game.physics.arcade.accelerationFromRotation(rotation, this.accelerationSpeed, this.body.acceleration);}else{	this.body.acceleration.setTo(0, 0);	}
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...