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.

DarkBASIC Professional Discussion / Waypoint Pathfinding

Author
Message
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 8th Jul 2010 17:24 Edited at: 10th Jul 2010 20:25
This is a project that I've worked on and off for a few months. It is waypoint utilities that allow you to place waypoints' connect them and use them. It's great for pathfinding for enemies throughout enclosed areas with lots of turns and bends. It uses the A* algorithm to successfuly find the shortest possible route to a destination. Although it still needs some improvement, I think it's good enough to post about.
All you need is to call 4 functions to setup and use the waypoints.

WP_Setup(amount) 'Call this first before anything, the amount is the maximum waypoints you have.
WP_MakeWaypoint(Waypoint Num,X,Y,Z) `This makes the waypoint and places it. Make sure when creating waypoints to not skip numbers.
WP_ConnectWaypoints(WP1,WP2) `This connects waypoints together
WP_MoveObjToPos(obj,x,y,z) `This gets called up in the main loop. It moves the object along the waypoints to get to the x,y,z position.
WP_DisplayWaypointNumber() This displays the waypoint number on the screen where it is located.
WP_DrawConnections() This draws the waypoint connections visibly.

UPDATES:
7/10/10: Fixed bug where object would follow a path into a dead-end

Heres the utility


READ:
-So far you can't have more than 100 waypoints at one time yet.
-You can't attach a waypoint to more that 4 other waypoints.
-When you attach a waypoint, they are attached both ways so if attaching waypoint A to B you only need to call the connect function once. No need for calling it up to attach B to A and A to B.

Here's a demo.


Screenshots:




If it hasn't exploded yet, I haven't touched it.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Jul 2010 00:58
Wow, this looks like a really useful bit of AI code!!

I'll certainly be having a good look at this!!

GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 9th Jul 2010 01:37
The syntax you have listed in your post for WP_MakeWaypoint leaves out the X and Y parameters. This confused me greatly until I read your code and saw that they were actually there.

Tagging this for future use. Code looks very well organized and I can most likely use this here soon.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 9th Jul 2010 18:04 Edited at: 9th Jul 2010 18:05
Well I got most of it down but I need to work on it a little to have it check for dead ends.
GIDustin, just fixed that.

If it hasn't exploded yet, I haven't touched it.

Login to post a reply

Server time is: 2026-07-25 08:30:02
Your offset time is: 2026-07-25 08:30:02