How would you make an object move along a drawn path ?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

How would you make an object move along a drawn path ?

Post by Roland_Yonaba »

Hi Lövers,

Well, I was thinking about making a short game, (just a random idea I got)...
In some part of the gameplay, an object might have to move following a drawn path.

My two concerns are :
1. Let the player draw his desired path, using a mouse, pressing down a button, for instance.
2. Make the object move precisely along that path.

How would you do this ? I am actually looking for elegant and efficient way to do it.
I may have some ideas, and I am pretty sure they will work :

* Display an empty buffer, get (each update cycle) pixels where the mouse has been hovering, and mark them as so on the buffer,
while list their (xi,yi) coordinates in a table which will be used by the object to move...

* Or just store the first pixel (x1,y1) coordinates (when the player started pressing down the mouse button),
while *still* marking the others pixels where the player will be hovering with the cursor.
Give (x1,y1) to the object.
Then it will move by steps, trying to detect each step looking in neighbourings pixels the next waypoint (previously marked) and step there.

Though, both of these methods appears quite expensive, to me.
Do anyone have interesting ideas ?
User avatar
juno
Citizen
Posts: 85
Joined: Thu May 10, 2012 4:32 pm
Location: London

Re: How would you make an object move along a drawn path ?

Post by juno »

If I were to do this, I would use your first solution.
Just record the mouse position at each update. Although I cant imagine it being too process heavy, you could always reduce the cost of processing by recording the mouse position after longer periods or distances instead, depending on how accurate you want the object to follow the path.
wat ya mean she's in another castle!?
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: How would you make an object move along a drawn path ?

Post by Kadoba »

Yeah I can't imagine it would be very resource heavy at all. Both process time and memory wise. I just did a quick test. I put the x and y value of the mouse in an array every 20th of a second. After 10 seconds it only took up 55kb. So at that rate it would take 3 minutes to take up 1MB of memory.
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: How would you make an object move along a drawn path ?

Post by richapple »

I agree: the simplest way to do so would be just recording positions and linearly interpolating between them one by one
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: How would you make an object move along a drawn path ?

Post by Ref »

You could create a ring buffer, the size of which (along with the sampling rate) determining the delay between mouse and object movement. Memory useage would be constant and controlable.
brad87uk
Prole
Posts: 3
Joined: Wed Jun 13, 2012 4:15 pm

Re: How would you make an object move along a drawn path ?

Post by brad87uk »

Ref wrote:You could create a ring buffer, the size of which (along with the sampling rate) determining the delay between mouse and object movement. Memory useage would be constant and controlable.
this would be my method..

first post btw so hello :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests