Page 1 of 1

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

Posted: Fri Jun 08, 2012 9:49 pm
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 ?

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

Posted: Sat Jun 09, 2012 12:56 am
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.

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

Posted: Sat Jun 09, 2012 2:49 am
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.

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

Posted: Sat Jun 09, 2012 9:25 am
by richapple
I agree: the simplest way to do so would be just recording positions and linearly interpolating between them one by one

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

Posted: Sat Jun 09, 2012 1:25 pm
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.

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

Posted: Wed Jun 13, 2012 4:25 pm
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 :)