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

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
italomaia
Prole
Posts: 6
Joined: Fri Dec 25, 2009 3:46 pm

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

Post 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!
andrew.207
Prole
Posts: 19
Joined: Sat Jun 08, 2013 7:27 am
Location: Melbourne, Australia

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

Post 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
http://www.atunnecliffe.com/
Bitcoins? 1LHn9yaErCakYD2iGwCyLungiC7ACxRUW8
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

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

Post by Roland_Yonaba »

Tweening ?
Plus, The Great Kikito has a library for that. :)
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests