Move from one point to another

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Move from one point to another

Post by xFade »

Lets say I create an image right?

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 :P)

Code: Select all

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
Help is appreciated ^.^
(ง'̀-'́)ง
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: Move from one point to another

Post by HugoBDesigner »

This should work:

Code: Select all

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.
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Re: Move from one point to another

Post by xFade »

It doesn't work and this is what is happening with your code.

The red lines represent the trails of the airplanes.
Attachments
test.png
test.png (81.29 KiB) Viewed 2579 times
(ง'̀-'́)ง
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: Move from one point to another

Post by DaedalusYoung »

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.
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Re: Move from one point to another

Post by xFade »

Yea I was trying to implement that to my equation.
(ง'̀-'́)ง
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Re: Move from one point to another

Post by xFade »

Here is an update on the plane's patterns :P
Attachments
test2.png
test2.png (80.76 KiB) Viewed 2570 times
(ง'̀-'́)ง
User avatar
CrackedP0t
Citizen
Posts: 69
Joined: Wed May 07, 2014 4:01 am
Contact:

Re: Move from one point to another

Post by CrackedP0t »

Would you mind outlining the airplane table?
/人 ◕‿‿◕ 人\
Here, have an umlaut. Ö
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 89 guests