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 / Another enemy AI Problem

Author
Message
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 12th Mar 2010 22:02 Edited at: 12th Mar 2010 22:06
I'm making a waypoint system for my game but this is a problem I can't seem to solve. I need it so that the program looks for the next logical waypoint for the object to move to by comparing the distances between the waypoints,objects, and waypoints to objects. For some reason it skipps certain waypoints and then goes into a loop moving between the same waypoints over and over again.
This is my entire waypoint movement function

O_O2 is the distance between the target object and the moving object
O_WP is the distance between the moving object and the waypoint
O2_WP is the distance between the waypoint and target object



If it hasn't exploded yet, I haven't touched it.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Mar 2010 17:57
Too much code to digest by looking at it so I'll point stuff out from my own experiences:

You should have a "destination" waypoint.
Each waypoint will need a list of all the other waypoints and "Nodes" for which it is connected to the ones nearest it.
Each "Node" has it's own list of the waypoints:

(I'm assuming no Waypoint will have more than 4 others attached to it.... the "4" is the number of nodes)
Each "Node" will have a number of jumps to "whatever" waypoint. So you can see that some "paths" are shorter than others. As long as when the object is "at a waypoint" it will make a decision to find the "shortest" path to the "destination" and go to the next waypoint until it's at the "destination".

You can make the NumberOfJumps(,) a BYTE or a short to take up less memory....

The fastest code is the code never written.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 18th Mar 2010 22:25 Edited at: 18th Mar 2010 22:43
Well I first off made my code a lot easier to read but anyways, I know that I have to store all of the possible waypoint paths from the object but how would I add together the distances without having to type every possibility?
This is what I have to calculate the paths.


If it hasn't exploded yet, I haven't touched it.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 19th Mar 2010 00:54 Edited at: 19th Mar 2010 00:55
The way I did it was I made a nested loop. There may be some way to do it better, but I'm not sure how.
psudocode:


I hope this gets you going in the right direction. Your post has reminded me that I have not yet made a waypoint plugin..... I should do so soon.

EDIT:
I just read your above post! You are doing something like what I just wrote.....

The fastest code is the code never written.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 19th Mar 2010 04:16 Edited at: 19th Mar 2010 04:27
Ok. Try this out....

The fastest code is the code never written.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 19th Mar 2010 22:55
Well I'm trying to code my own waypoint system but I can't figure out for that code how I would go from each waypoint to waypoint based on distance and how the their attached through each node.

If it hasn't exploded yet, I haven't touched it.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 19th Mar 2010 23:43
The Nodes(WP,Node) refers to the attached waypoint; so that if you had waypoint#1 attached to waypoint#2 then one of the nodes ( Nodes(WP,Node) ) on each waypoint would point to the other waypoint...... I hope you understand what I'm saying.

Here's a scheme to accomplish that:

-make some waypoints using MakeWaypoint(x,y,z)
-attach them togather using AttachWaypointToWaypoint(WP1,WP2). You only have to make a single connection using WP1,WP2 or WP2,WP1. It doesn't matter the order.
-if your NPC is at a waypoint (we'll call it WP1) and he wants to go to WP9, then you call FindShortestPath(WP1,WP9) and the return value is the Node that the NPC will go thru (while on WP1) to get to the next waypoint on it's way to WP9. So you could point it at WaypointLocation(Nodes(WP1,FindShortestPath(WP1,WP9))). You would have to use each value (x,y,z) to do the pointing.
-when your NPC gets to the next waypoint simply repeat the process above using the waypoint the NPC is currently on and the destination is still WP9.

Perhapse a look at this code will help:
I think I simplified it with showing a path.

The fastest code is the code never written.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 19th Mar 2010 23:52 Edited at: 19th Mar 2010 23:52
Thanks for clearing that up. I'll post here if I have any more questions.

If it hasn't exploded yet, I haven't touched it.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 22nd Mar 2010 02:08 Edited at: 22nd Mar 2010 02:51
Okay now I got nodes set up but it still doesn't work. The object that is supossed to move stays on one waypoint and can't find the node to go to.


If it hasn't exploded yet, I haven't touched it.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Mar 2010 15:23 Edited at: 22nd Mar 2010 15:31
Did you try emplimenting my utility? It seems as though you just made one yourself. I'll look at the code to see if I can figure out the problem. Just try my code in your app; you might like it.

EDIT:
I don't see where you translate all the distances to each waypoint from each waypoint.

The fastest code is the code never written.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 22nd Mar 2010 22:07
I only translated the distance from the node waypoint to destination waypoint. I want to try to write my own code because it will help me learn more.

If it hasn't exploded yet, I haven't touched it.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Mar 2010 01:04
Quote: "I want to try to write my own code because it will help me learn more."

That's the way I like it too.

Ok.
For your object to navigate from pointA to pointZ, it has to go through all the ones in between, so it's important to have distances and "direction" to make it work. The "direction" is the node on a waypoint. Think of a node as a connecting line between waypoints. This node stores only which waypoint it is connected to.
BTW all of this that I am talking about is the same stuff you would learn when dealing with networks-- except that they don't deal in distance; they deal with number of jumps to determine the "shortest path".
Now that you have the "connection" info, you need to know the distance from each node connected to each node.
You have most of this already. Now check out my UpdateWaypoints() function-- this is the most important function. This is the "nested loop" I refered to earlier. What it does is it takes each existing waypoint one at a time. For each waypoint, it looks at each attached waypoints info (each destination to each waypoint) and adds the distance to it's distance from to that waypoint and then stores that info..... Hope you are following me. You may understand it by studying that function, or you can read up on network paths.

I had a network class that I took the principle from. Good luck! And let me know if you still have trouble. I love to share the knowlege.

The fastest code is the code never written.

Login to post a reply

Server time is: 2026-07-26 23:40:55
Your offset time is: 2026-07-26 23:40:55