The faster an object goes, the slower it will accelerate, going from 0 to 50 takes a lot less time then going from 50 to 100,
How do I calculate that, though?
EDIT: Extra details,
This specific scenario is about a space ship, here is the code I'm using for giving it a constant acceleration, which I'd like to rewrite so that the faster it goes, the slower it accelerates.
EDIT2: Thanks to Sam Hocevar the code I showed was flawed, I've updated the code.
var dx = this.x - this.destination.x,
dy = this.y - this.destination.y,
r = Math.atan2(dx, dy) * -1,
this.speed += this.acc;
if(this.speed > this.maxSpeed){ this.speed == this.maxSpeed; }
this.x = Math.sin(r) * this.speed + this.x;
this.y = (Math.cos(r) * this.speed * -1) + this.y;
Old code.
this.sx += (this.destination.x > this.x) ? this.acc : -this.acc;
this.sy += (this.destination.y > this.y) ? this.acc : -this.acc;
if(this.sx > this.maxSpeed){ this.sx = this.maxSpeed; }
if(this.sx < -this.maxSpeed){ this.sx = -this.maxSpeed; }
if(this.sy > this.maxSpeed){ this.sy = this.maxSpeed; }
if(this.sy < -this.maxSpeed){ this.sy = -this.maxSpeed; }
this.x += this.sx;
this.y += this.sy;

-1you added indicate something is wrong. The first-1can be omitted if you compute the direction asdestination - positioninstead ofposition - destination. The correct way to callatan2isr = Math.atan2(dy, dx)(notice the argument order). Then thexcomponent isMath.cos(r)and theycomponent isMath.sin(r)and all the-1's can go away. – Sam Hocevar May 4 '12 at 12:44