Image's x = 50 and its y = 310. Now I want to move it to lets say (40,80)...
How would I make it move smoothly and make it come to a complete stop once it reaches those coordinates.(Make it work for different coordinates not only for the example coordinates )
function updateAirplane(dt)
for _,v in ipairs(airplane) do
v.x = v.x -- Issues here
v.y = v.y -- Issues here
if v.x == v.x1 and v.y == v.y1 then
landed = true
end
end
end
function updateAirplane(dt)
for _, v in ipairs(airplane) do
v.x = v.x + (v.x1-v.x0)*dt*v.speed
v.y = v.y + (v.y1-v.y0)*dt*v.speed
if v.x0 > v.x1 and v.x > v.x1 then
v.x = v.x1
elseif v.x0 < v.x1 and v.x < v.x1 then
v.x = v.x1
end
if v.y0 > v.y1 and v.y > v.y1 then
v.y = v.y1
elseif v.y0 < v.y1 and v.y < v.y1 then
v.y = v.y1
end
if v.x == v.x1 and v.y == v.y1 then
landed = true
end
end
end
If not just let me know
Oh, and, for this to work, you'll need two more variables: v.x0 and v.y0. They'll be where the Airplane starts.
You probably want a linear or cosine interpolation, see http://www.love2d.org/wiki/General_math for the lerp and cerp functions for this. Just add a counter going from 0 to 1 and use that as t value.