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 ?
How would you make an object move along a drawn path ?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: How would you make an object move along a drawn path ?
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.
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!?
Re: How would you make an object move along a drawn path ?
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 ?
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 ?
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 ?
this would be my method..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.
first post btw so hello
Who is online
Users browsing this forum: No registered users and 16 guests