Page 1 of 1

Moving from one point to another with acceleration and...

Posted: Sun Jan 05, 2014 10:01 am
by italomaia
Hello folks! I'm trying to make a car move from one point to another with acceleration and deacceleration. It should work like this:
I have cords x1,y1 and x2,y2 and I want my car to move from one point to another starting in speed 0 and ending in speed 0 with an acceleration and deacceleration behavior. I have no idea how make sure the deacceleration start at the right moment so that "jumps" in the screen do not occur.
Any help here is appreciated. Thanks!

Re: Moving from one point to another with acceleration and..

Posted: Sun Jan 05, 2014 11:03 am
by andrew.207
This seems to fit your description.

Here. Getting error "Sorry, the board attachment quota has been reached." when I try to attach, please excuse dropbox link.

I accomplished what you asked for by accelerating until the block is half way between the origin and the destination, and then decelerating at the same rate. It would be easy to increase the acceleration rate and add a "maxSpeed" variable that would make it look less... mathematical.

Code: Select all

function player:update(dt)
  xDiff = self.desire - self.x
  if xDiff > (self.desire - self.origin)/2 then
    self.xSpeed = self.xSpeed + self.accelaration * dt
  else
    self.xSpeed = self.xSpeed - self.accelaration * dt
  end
  
  self.x = self.x + self.xSpeed
end

Re: Moving from one point to another with acceleration and..

Posted: Sun Jan 05, 2014 1:47 pm
by Roland_Yonaba
Tweening ?
Plus, The Great Kikito has a library for that. :)