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!
Moving from one point to another with acceleration and...
-
- Prole
- Posts: 19
- Joined: Sat Jun 08, 2013 7:27 am
- Location: Melbourne, Australia
Re: Moving from one point to another with acceleration and..
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.
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
Bitcoins? 1LHn9yaErCakYD2iGwCyLungiC7ACxRUW8
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Who is online
Users browsing this forum: No registered users and 5 guests