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 Discussion / What is a waypoint?

Author
Message
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 12th Dec 2008 17:25 Edited at: 12th Dec 2008 17:52
ok so i was just wondering i'm not far enough if my game to start thinking about starting AI i don't think but i thought while i was thinking about it i would find out what was put into it.

well I'v seen stuff on here about Waypoints i have no idea what that is anyhelp?

[Edit]
Ok well I have been searching google for stuff on it but its all c++ stuff. well from what i can see it requires nodes? i don't know what they are but it looks like they are just Places for the enemy to move. but if thats how it works then the hole map would have to b covered in them hm

Btw just in case you read my other post and are thinking he already asked for this and was told it would b covered on a forum thread. yes well i don't want a tutorial i just want to know what like the things that people talk about are. like the waypoints and nodes and stuff.
[/edit]
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 12th Dec 2008 18:55
It's pretty much just a set of coordinates, take a zig zag line for example.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Dec 2008 19:49
Like Ashingda 27 said, it's basically a point. It's the "way" to go. A set of waypoints usually represents a path from one point to the next. So a waypoint is basically a set point you go to, from where you are.

A node is a division or an index in a set. If you have 10 waypoints for example, each set of coordinates could be called a node so you could have 10 nodes; the node isn't the coordinates of the points, but it's the index of the waypoints.

Enjoy your day.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 12th Dec 2008 20:19 Edited at: 12th Dec 2008 20:43
The definition of a "waypoint: ~ a point along the way, is one thing. How to put them to use in AI is another. So now that you understand what a waypoint is, you need to understand what there role in AI is, what a waypoint graph is etc...

Here is a good article on Terrain Reasoning for 3d Action Games

some quotes from the article
Quote: "A popular and custom means to describe terrain are waypoints (and similar concepts such as cells or grids - see [Reece], [Snook]). Waypoints represent the subset of the terrain accessible to the player and AI. The connections between these waypoints denote viable movement. And the graph created by the waypoints and their inter-connections expresses the valid paths.

Often, these waypoints are annotated with the presence of nearby power ups. Sometimes, the waypoints are part of more abstract concepts like areas and portals. Thus, waypoints are a handy and versatile terrain representation. Nevertheless, the AI typically ignores to reason about them (except for the occasional path finding).
"


Quote: "The remainder of this paper discusses how to reason about terrain based on the waypoint graph."


Waypoint Calculations
The direct relation between tactical concepts and the waypoint graph enables us to turn these concepts into computable properties. For meaningful results, those computations should resemble the human tactical interpretation.

A waypoint has four different kinds of characteristics that all should be taken into account:


* The local environment. Waypoints describe, for example, how dark the location is, which types of movement are required (crouching, swimming, using a ladder), whether a door or button entity is present.
* The membership(s) of higher-level terrain concepts. Waypoints may be grouped to represent terrain concepts such as a room, a lake, or the blue team's base.
* The relations with other waypoints. Waypoints have relations with other waypoints: is there a valid line-of-sight, how long does it take to get from one waypoint to the other.
* The focus (in the relations with other waypoints). A waypoint whose relations, such as line-of-sight or easy access, are clustered primarily in a single narrow direction has focus in that direction.



~Zenassem
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Dec 2008 14:49
Some good info here.

You could store your waypoints in an array like this...

So like Latch said, each waypoint number is an index; using the waypoint number we extract the x and y position of the corresponding waypoint from the arrays.

A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 13th Dec 2008 23:11
Ok i see but i'm getting a error

No such array dimension initialised at line 6
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 01:20
That error is from this line

line Way_x(waypoint-1),Way_y(waypoint-1),Way_x(waypoint),Way_y(waypoint)

when waypoint=0 (waypoint-1)=-1 and you can't have an index of -1

~Zenassem
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 14th Dec 2008 01:27
That cant be because there's also this like that prevents it from getting an error.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 02:06 Edited at: 14th Dec 2008 02:17
Quote: "That cant be because there's also this like that prevents it from getting an error."


Thanks! Missed that. I can't run the code where I am, so I don't know what the problem would be. I'll have to take another look.

edit
the problem is when waypoint=4 when you dim an array like

you get 4 elements indexed 0-3.

So in the following lines (when waypoint=4) the program is accessing elements that don't exist (highlited in bold).

Way_x(waypoint)= rnd(640)
Way_y(waypoint)= rnd(480)
line Way_x(waypoint-1),Way_y(waypoint-1),Way_x(waypoint),Way_y(waypoint)

to fix change the dim values to 5


~Zenassem
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 14th Dec 2008 02:23
I did not get an error when I ran it.

Obese's line is draw from waypoint-1 to waypoint and the first line which would have checked negative in the waypoint is prevented.

@Caleb
I'm not sure what exactly went wrong but im assuming you copy and pasted it wrong?.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 02:26 Edited at: 14th Dec 2008 02:28
Yes but when waypoint=4 it accesses and element in the array that doesn't exist in 3 different lines.

Way_x(waypoint)= rnd(640)
Way_y(waypoint)= rnd(480)
line Way_x(waypoint-1),Way_y(waypoint-1),Way_x(waypoint),Way_y(waypoint)

Dim Way_x(4)
Dim Way_y(4)

each createas an array of four elements indexed from 0 to 3
Way_x(0)
Way_y(0)
Way_x(1)
Way_y(1)
Way_x(2)
Way_y(2)
Way_x(3)
Way_y(3)

So to have Way_x(4)=something will cause an error

~Zenassem
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 14th Dec 2008 03:32
An array with an index of array(4) should have.

If I'm not mistaken
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 03:58 Edited at: 14th Dec 2008 04:04
I STINK , and you are right. What a crazy language. Finally home and will test the code. lol


The code works AS IS! Not sure why you were getting an error.

That's the last time I try to answer something without being at my compiler!!! "IanM I am not!"

~Zenassem
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 14th Dec 2008 06:56
Quote: "That's the last time I try to answer something without being at my compiler!!!"
LOL, I've said something like that befor.
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Dec 2008 17:05
I wrote that without DB so I was thinking oops! what have I caused here! good to here it works though
and it draws the lines properly?

A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 15th Dec 2008 00:43 Edited at: 15th Dec 2008 00:55
well putting Way_X(4) and Way_Y(4) to Way_X(5) and Way_Y(5) works great! thanks!

so with this info just wondering does this meen I'm going to need to put them all over my map for AI to work well???????
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Dec 2008 18:27
Quote: "well putting Way_X(4) and Way_Y(4) to Way_X(5) and Way_Y(5) works great! thanks!"

huh? there is no 5, that's probably why you got an error.

Quote: "so with this info just wondering does this meen I'm going to need to put them all over my map for AI to work well??????? "

No, they were just random point, I couldn't be bothered to plot out a proper route.
Have you played the races in GTA? Well those markers you go through are waypoints, the whole point of a waypoint system is for a path that isn't a straight line.
An AI routine would be something like: go to this waypoint, look for enemies, if no enemies proceed to this waypoint, etc.

A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 15th Dec 2008 20:51
ok but for that you would still need alot of them all over for the map so the enemy would have the waypoint to move to wouldn't you? i was thinking like a checker game but on a 3d map? where u have waypoints inside a certain square type radius thing like this

. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .

see thats just what i was thinking
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Dec 2008 22:20
If you're going to make a grid based game it's best to use an array like this...

I've made a board and initial checker positions for you; it's not 3D but you can apply this to 3D when you've worked out all the hard stuff. The array stores the state of every square on the board (0=empty, 1=white, 2=black), this is an a good way to do it and will make AI much simpler.

A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 17th Dec 2008 23:08 Edited at: 17th Dec 2008 23:15
yes but i'm not making a board game. i was talking about applying that same idea to a 3d First person shooter.

so those dots in my last post would b the heads up display of the map for my FPS
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Dec 2008 00:05
So you're making a 3D FPS that's like checkers?
could you explain in more detail?

A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 18th Dec 2008 19:35 Edited at: 18th Dec 2008 19:39
lol sorry no its a first person shooter just a normal fps with guns and enemys you shoot. but wat i was saying was if i used the same waypoint idea as checkers where the waypoints were set up like a checker board. see?


[edit]

wait here i figured out a better way to word the question. haha

so do i need to set up the waypoints like a GRID (checker board just confuses people) all over the map? lol

[/edit]
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 19th Dec 2008 14:59
Well it depends how your monsters are going to act and how intelligent you want them to be, are they going to be travelling on set paths or wandering on their own?
I love grids, they just make everything more logical, so that's what I'd use. You could plot out your level on a grid: make an array to store data for your level; what kind of terrain each square is etc. You could even have multiple arrays storing different data about your level for specific squares; lighting intensity, how the player traverses the square (swimming or walking etc), spawning points for enemies. Just make sure you make enough different arrays with good names to help you keep track of the data without having to remember what different dimensions/fields represent.
From here you can make another array for waypoints that will reference squares in the level array.


Goke of the day: I coded an AI replica of Steve Irwin. It crashed because of a string array.
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 19th Dec 2008 22:06 Edited at: 19th Dec 2008 22:34
Ok awesome ya i think for my first AI deelio i won't let them walk freely that would b harder so i'll probly just plot the paths.

one question. ok so i'v seen things about A* algorithms for AI but havn't found enough to help me what is that? all i'v herd is that its algorithms to calculate the next waypoint but i'v never seen examples

or are there better ways to do it? how would you go about plotting paths. its easy to send it to another waypoint but what about sending it the write one to go up stairs?


Just a question. would it be something like this?


Check to see if Objective is higher the the main floor.
If so Check for the closest Staircase.
Set that as objective
Then (or if original objective was on ground floor)
Check for the closest waypoint
Check to see witch is closest to the objective
Move to that waypoint
Repeat

And then if you do go up stairs Check and see if objective has gone up another flight of stairs. if so repeat the stair function?


That just popped in my head idk if thats even close. that sounds like alot of distance equations sounds like it would eat speed
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Dec 2008 05:06 Edited at: 24th Dec 2008 06:03
Strangely I've never written a pathfinding routine!
But I'll give it a go anyway
Here's a simple map I drew to help visualise things...

We have a green start, red finish, white roads and black walls. We need to get our monster from green to red passing over only white squares. This map is stored in an array...

We will also need to make a second array with the same dimensions to act as our monsters "brain", after all he needs to know where he's been...


Junctions are where the decisions are made, everywhere else we just have to remember which direction we're moving in.
The simplest way we can do this is to mark (in the monster brain) which squares we've traversed, when we come to a junction we take one of the routes and if that fails we come back to the junction and try a different route. If we increment the "footfall" value of a square each time we visit it then we can make a path by selecting the lowest value adjoining square, that way if even all routes from a junction fail we can retrace our steps all the way back down the road before the junction to find the next available route.

Ok, lets test this formula out with our maze.
We start on the green square and add one to its footfall value, we then look at the adjoining squares and see only one road so we take it. There's only one route up the winding path to the first T-junction, when we reach it we have to make a decision to go north or south, for arguments sake lets try going south first.
We follow to road round and up to the dead-end, since we're at a dead-end we mark the square again - as if the monster is stamping his feet in frustration - we do this to make sure the algorithm doesn't decide to come back here. Now the lowest possible square is to the right, we take it and now because our dead-end is a 2 the path back to the junction is the lesser (being 1).
We eventually get back to the junction. Now we have a 1 to the west a 2 to the south and a 0 to the north, so we go north. If you repeat the process you'll see we eventually get to the finish.

[edit]
Extra Lesson: Recursive Functions
Path finding is the perfect situation to use a recursive function - if you haven't learned functions yet I'd steer clear as it can get a bit complicated and confusing.
A recursive function is one that calls itself; this seems a strange idea at first, surely this would be an endless loop of function calls? But no, we have a condition inside the function that determines whether the function recurs or not. But if the function is calling itself how can the outcome of the condition change? That's where the clever part comes in. On the second call we send different parameters to the function, and so we alter the outcome of conditions within the function. The simplest of examples produces a FOR-loop type effect...

Hope it works, no testing!
The novel thing here is that the circles are only draw once the radius reaches 0 and can't get any smaller. When the function ends it can't just go back to the main program, it has to re-trace it's steps back through the previous calls of the function drawing the larger and larger circles it left behind as it goes.

Here's a program I made a while ago that uses recursion.
You can do some pretty cool things with recursion.



Goke of the day: [Q]What's a coders' favourite part of an orchestra?
[A]The strings.
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Dec 2008 07:19
Ok i don't quite understand how you could store the map in a array?
Do you mean storing locations on the screen that corrospond to the map and then setting them to 1 or 2 (white or black)? if so then i understand completly haha

For the maze wouldn't it be easier to have a array to store the correct way to go and then if the Monster tried to go the wrong way instead of having to go alll the way to the end then turn around because wouldn't that make it(if it was u against the enemy) really easy to win if he always searched every available root? lol

and in the function part i see what you meen but one question i'v never understood the select endselect and case commands what do they do?
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Dec 2008 14:36
Quote: "Ok i don't quite understand how you could store the map in a array?
Do you mean storing locations on the screen that corrospond to the map and then setting them to 1 or 2 (white or black)? if so then i understand completly haha"

Not neccessarily locations on the screen but yes that's the idea. It's the same idea as grid references on real life maps; you have an x and y coordinate and that points you to a particular square. The great thing about arrays is that each square (or field) in the array acts like an independent variable, in fact that's what it is: an array of variables! This means that we can put whatever we like in each field and they don't have to follow any logical order. Ideal for making maps!
I say "not neccessarily on screen" because our map isn't bound to pixels on the screen, we can put it wherever we like and scale it to any size we like, as long as we maintain the relative positions of each square we can recognise our map.

The reason we need a second map (the monster brain, that acts as a kind of overlay) is to separate what this individual monster knows from the rest of the game world; this lets us have multiple monsters all going on their own paths! Also, if we want to start a new path to a different waypoint we simply clear the monster brain, no editing of the map is required. The brain has the same dimensions as the map but we don't need to store where roads and walls are because the monster will refer to the map for that information. The data we store is quite different to the map, 0 no longer means wall and 1 no longer means road, the fields in the brain are simply used to store the monster's foot-fall.

Quote: "For the maze wouldn't it be easier to have a array to store the correct way to go and then if the Monster tried to go the wrong way instead of having to go alll the way to the end then turn around because wouldn't that make it(if it was u against the enemy) really easy to win if he always searched every available root? lol"

Good! You are thinking about this.
Well the clever thing is all we need to do is change when the monster moves. Instead of having the monster walk into every dead-end, we send an imaginary monster (or probe) to seek out the best route before the monster has lifted a foot. It's the same method but all the calculating is done first, then the monster moves. Sometimes with complicated mazes this can take a while, so to keep things flowing we could move the monster to the next junction while the probe is finding the best route fromt the same junction - remember it will take time for the monster to get to the junction, and in that time the probe can wizz about and find the next route. This requires some clever coding that will advance the probe one step at a time instead of finding the whole route at once.

Quote: "and in the function part i see what you meen but one question i'v never understood the select endselect and case commands what do they do?"

The SELECT command let's us examine a variable without having to keep referring to it. Just like in that sentence; the second time I mentioned the variable I just called it "it" because I'd already stated I was talking about it. I did it again . And again in a very abstract way!
Just like in language, SELECTing a variable makes it very easy to say many things about it without having to explain too much. We can tell DB what to do if "it" is a certain value and even what to do if "it" is none of the values we've specified! That's a very useful part of the command.


Goke of the day: [Q]What's a coders' favourite part of an orchestra?
[A]The strings.
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Dec 2008 17:43
oh ok i see what you mean Thanks




Oh thats a Great idea then you can just change the speed of the probe for different diffuculties!


Ok so it is similar to a if statement? like in yours:



You are saying that Ring is reffering to the variable? or is it saying if pole(source)=1 then if ring=1 then if ring=2 then if ring=1 etc.?
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 25th Dec 2008 13:37
Quote: "Ok so it is similar to a if statement? like in yours:

+ Code Snippet
Select Pole(source)
Case 1 : ring = 1 : Endcase
Case 2 : ring = 2 : Endcase
Case 3 : ring = 1 : Endcase
Case 4 : ring = 4 : Endcase
Case 5 : ring = 1 : Endcase
Case 6 : ring = 2 : Endcase
Case 7 : ring = 1 : Endcase
Endselect

You are saying that Ring is reffering to the variable? or is it saying if pole(source)=1 then if ring=1 then if ring=2 then if ring=1 etc.?"

Not quite, the cases are referring to the variable...
Case 5 : ring= 1 : Endcase
This means: In the case of the selected variable equaling 5, let ring equal 1.
Each case is independent and will only act out the code in between the CASE and ENDCASE if the case is true. You could also have a CASE DEFAULT which is executed if no other cases are true...

I'm not sure what that would do to the program but if Pole(Source) were less than 1 or greater than 7 it would assign ring the value 0.

Select Case would probably be useful for your AI as you'll be doing lots of checking.


Goke of the day: [Q]What's a coders' favourite part of an orchestra?
[A]The strings.
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 25th Dec 2008 19:37 Edited at: 26th Dec 2008 22:53
oh i see! that would be very usefull!


[edit]

i'm a complete idiot! haha i was thinking of the waypoints at at the corners of the squares hahahaha i just figured it out lol.

i was thinking this would be a hole lot harder till now(although it still is going to be difficult)

[/edit]
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 26th Dec 2008 23:04
jw what would be the easy way to check for the closest waypoint because a for next doesn't seem to work i tried and i can't get it to work. i made a simple set of waypoints(a grid all over the screen) and move a circle on them accros the screen haha quite simple but it helped me figure it out. heres my code any help. because the waypoints on each side of the circle are all gunna be the same distance appart that why i don't understand


[edit]

whoops sorry bout the double post

[/edit]
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Dec 2008 23:59
Where's your code?


Goke of the day: [Q]What's a coders' favourite part of an orchestra?
[A]The strings.
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Dec 2008 04:13
whoops again sorry lol well i looked over some other resources on pathfinding and i tried to put something together what i did was get the waypoints above below and to each side(I'm not gunna go diagnly makes things simple for now) and then put them in a seperate array and then found the one closest to the goal then moved it to there then did it again. but i'm getting a error after around the third move "Array accessed out of bounds at line 83" heres the code (for real )

Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Jan 2009 20:07
Haven't checked your code but it sounds like your monster comes to the edge of the maze and then when the AI goes to check the surrounding squares one of them doesnt exist, DB panics and explodes!

A neat trick is to make a perimeter wall in your array, an extra two rows (top and bottom) and extra two columns (left and right), this ensures that your monster will never get to the edge and so this problem will never occur. You can even hide this perimeter wall so that the user is unaware of the trick.

Choosing the nearest square to the goal is dangerous because if that square is a dead end your monster is stuck! Even if you have some logic like our footfall "brain" your monster will keep making the decision to go back down the dead-end road.

I was playing around with it myself and made another array that stores the direction the monster went from that square, looping the pathfinding routine until the monster reaches the target leaves you with a "signposted" route from start to finish.

Adding layers to your AI is a fun way to give him new abilities, the key is having layers that work independantly and communicate unique data to help with decision making.


Goke of the day: [Q]What's a coders' favourite part of an orchestra?
[A]The strings.
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 6th Jan 2009 20:21 Edited at: 6th Jan 2009 21:04
yes that if this was a game he would get stuck but at this point i'm not making a game. i'm getting myself familiar with waypoints and AI so at this point it doesn't matter much as there are no walls i'm just getting a circle from point a to point B. actually i had forgotten about this project (i got cot up with another thing that turned out to be a project) but i think i will start working on it again i will try adding another layer and see what happens though thanks



[Edit]

Ok i tried it but it didn't work.

I did figure something out though. instead of Going toward the Goal it's going away from it thats why it was saying array accessed out of bounds. The checking array was trying to check Map(1,X-1) and so on when X and Y were 0 it was trying to check negative numbers of a array whoops. Part where the X and Y were added to or subtracted from was inverted... lol

Login to post a reply

Server time is: 2026-06-25 09:07:16
Your offset time is: 2026-06-25 09:07:16