Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Waypoint/path following

Author
Message
MatriX
20
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 27th Oct 2003 02:25
Whats the best way to program an object to follow a waypoint data base (pre-determined path.)I'm using it to make a car follow a track but would also like to use it to make any entity follow a path.

This the approach that I took but I'm having problems:
I have all of the waypoints stored in a variable array.

I set the object to point to the next waypoint and used "move object" to traverse it between them. The problem is that the waypoints are real numbers like "534.4323,432.2422" and the object, although pointed at the waypoint never actually lands on it. I thought to subtract the distance from the object to the waypoint and if it's less than the next move distance then it will point to the next waypoint and start moving towards it and so on. Unfortunatley this isn't as precise as I'd like to be. In fact it's a little jumpy for obvious reasons when it reaches the next waypoint. Any suggestions?

In life try hard. Success does not come easy.
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 27th Oct 2003 05:26
Game Creator and I are working on some ideas for way points on a track. The plan is to place the way points (X/Y/Z) with the custom track editor. The vehicles will drive towards the way points, but once they get within the 'way point zone' they will start picking up the next way point. This means that they're always running towards the next way point rather than trying to home in exactly on the current way point.

Of course, when they hit the last way point on the track they get sent back to the first way point in the loop. I don't have any code to share, yet. But, I hope that gives you some ideas.
--
TAZ
Kharnor
21
Years of Service
User Offline
Joined: 5th Jul 2003
Location: Australia
Posted: 27th Oct 2003 08:47
Here's what you could do:

If the object moves at a speed of 10 units, and it's 8 units to the next waypoint, then position it on the waypoint, turn it to the next one and move it 2 units.

Make sense?

Current project:
Adventure game for alienware comp (5% complete! I'm finally getting somewhere!)
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 27th Oct 2003 09:57
i just use a setup similar to detecting button clicks just test to see if an object is within a certain area then change it to move the next waypoint.


Go on, click on my signature image, you know you want to
Favourite smiley>>>
_THOR_
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Brasilia - Brazil
Posted: 27th Oct 2003 14:44
Hi,

I´ve just finished a game that does this.

Below is the main routine.
- paths in memblock;
- calculate distance between 2 points (dgn function);
- generate intermediary points;
- move with curveangle;
- at the end of the path, choose another one;

Flavio Bressan
http://www.geocities.com/defy.htm
MatriX
20
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 28th Oct 2003 02:23
I guess I wasn't far off then...I can use the pythag theory to find the distance but is there a better way to find the distance between two points? What is the dgn function?

Thanks all for the help!

In life try hard. Success does not come easy.
hexGEAR
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 29th Oct 2003 12:25
pythag is the best/easiest way, i'd stick with with if i where you , if you want another example of the waypoint method check this out click here only thing is that the object doesn't smoothly turn from one point to another, this would be easily implementable using the methods described above by zircher

David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 29th Oct 2003 13:38
What I do:

Have an array of waypoints

- Set the current waypoint to the one after the start, keep moving to the current waypoint.
- If we reach the current waypoint, set the current waypoint to the next waypoint.
-If we reach the the last waypoint, then set us at the beginning.

"The trouble with the French is that they have no word for 'entreprenuer'" - Pres. George W Bush
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Oct 2003 19:46
Look up bezier curves if you want smooth turning from point to point.
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 29th Oct 2003 20:57
Simple box collision could be easier than pythagoras if you don't need accuracy. My mini space battle 20 line demo has an example of waypoint-following code.

Once I was but the learner, now, I am the Master.
See my site for amazing games and demos!
MatriX
20
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 2nd Nov 2003 15:03
Thanks, appreciate the feedback everyone.

Yeah my main problem here is that now it doesn't turn smoothly from turn to turn. I knew this was a problem from the start however I was hoping to add tons of waypoints to make it un-noticable. I don't really like that solution although it's easy.

Phelax, I understand bezier curves very little other than using them in graphics programs like Corel. I'd like to implement them here. I could eliminate most of the waypoints by using this. Do you have links that would help? I appreciate it.

I wrote a small utility for Corel in VB that extracts the points of a path and writes them to a file. This is how I am getting my waypoints. I could have it generate a file with arc curves as well.

In life try hard. Success does not come easy.
D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 2nd Nov 2003 15:35
You could try my pathfinding method using more than one attractor(and switching them dynamically).
The big pro: no need to calculate collisions .
http://darkbasicpro.thegamecreators.com/?m=forum_view&t=17344&b=6

God is real, unless declared integer.
MatriX
20
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 3rd Nov 2003 06:37
Wow good stuff D Man. The pythag theorm I understand well but some of those other equations are beyond me. I will keep this doc handy however. I will definitly need to learn about A* in the future for some of my other ideas. Thanks!

In life try hard. Success does not come easy.
MatriX
20
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 8th Nov 2003 09:07
If I wanted to use two points to describe an arc ahd find a point in space along that arc, what type of math would I use? Can someone point me in the right direction?

In life try hard. Success does not come easy.

Login to post a reply

Server time is: 2024-09-21 07:38:15
Your offset time is: 2024-09-21 07:38:15