Bot path making
by Nathan Kent · in Technical Issues · 09/30/2007 (6:12 am) · 8 replies
How do you get a bot to make their own path to a destination? Is that even possible? Or would I have to make a veriety of paths, and have them randomly pic one?
About the author
#2
10/06/2007 (7:01 am)
Yeah, that's kinda what I was thinking, but I agree. To much of it would take a long time, but thanks for the idea!
#3
With A* you place your new Navigation markers and it will automatically link them by visibility and distance. You can then ask it how to get from where you are to where your going and it will tell you which point to head towards next. Because it takes visibility into account you will always walk a clear path.
Failing that I'd suggest writing a little intialization script that looks at all your path nodes and finds out which ones are really really close together (group them together in the intersection). Save this information in the node. Then when your bot gets to a node it can ask the node which paths it is "linked" to and choose a new path as it sees fit.
Finally to keep them from walking down the middle of the street, add a Width member to each one of your paths. If your width is always the same then skip that step. Then when a bot is traveling a path offset it's move destination positions by a value within width. If you want them to keep the same offset (for example a car stuck in a lane) then only set the width once at the beginning of movement. If you want them to zigzag randomize it at each node or even while they are moving between nodes.
10/06/2007 (9:59 pm)
@Nateck: Take a look at A* path finding. I believe there is both a resource for all-script and one that mods the engine itself. Its not all that hard to use. If you are licensees you can use this resource [url=http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8531]here[/b] which is very easy to plug in.With A* you place your new Navigation markers and it will automatically link them by visibility and distance. You can then ask it how to get from where you are to where your going and it will tell you which point to head towards next. Because it takes visibility into account you will always walk a clear path.
Failing that I'd suggest writing a little intialization script that looks at all your path nodes and finds out which ones are really really close together (group them together in the intersection). Save this information in the node. Then when your bot gets to a node it can ask the node which paths it is "linked" to and choose a new path as it sees fit.
Finally to keep them from walking down the middle of the street, add a Width member to each one of your paths. If your width is always the same then skip that step. Then when a bot is traveling a path offset it's move destination positions by a value within width. If you want them to keep the same offset (for example a car stuck in a lane) then only set the width once at the beginning of movement. If you want them to zigzag randomize it at each node or even while they are moving between nodes.
#4
10/10/2007 (10:59 am)
You can set the width property on paths? How?
#5
Under the dynamic properties just add a new variable named "pathWidth" or whatever and give it a value.
The in script you can access this variable just as if it were part of the object (well, it is).
Finally when you set your movement destination you will have to add your calculated offset. To obtain this you will probably need to get the directional vector between the current and next node, build a matrix and multiply your offset (which would be (someWidth, 0, 0)).
10/10/2007 (5:03 pm)
Its not a built in function but its something you can add.Under the dynamic properties just add a new variable named "pathWidth" or whatever and give it a value.
The in script you can access this variable just as if it were part of the object (well, it is).
Finally when you set your movement destination you will have to add your calculated offset. To obtain this you will probably need to get the directional vector between the current and next node, build a matrix and multiply your offset (which would be (someWidth, 0, 0)).
#6
10/11/2007 (3:45 pm)
I probably sound like an idiot, but what is a matrix? I know what they are in math, but I don't get how to appy those to TGE, I'm just learning this stuff.
#7
I am not the one to ask for a primer. I'm sure the information can be found on this site and others. Google is your friend.
I don't know how to work with matrices in Torque script but I bet the TDN can tell you that. Somebody else can probably tell you an easier way with a axis & angle thing.
If I have time I will give this a go and post it. But that might not be for a while.
10/12/2007 (3:19 am)
Its the same thing as in math. Your whole computer game is math. All of 3D is math. You need vectors and matrices or make it work or it just don't.I am not the one to ask for a primer. I'm sure the information can be found on this site and others. Google is your friend.
I don't know how to work with matrices in Torque script but I bet the TDN can tell you that. Somebody else can probably tell you an easier way with a axis & angle thing.
If I have time I will give this a go and post it. But that might not be for a while.
#8
10/12/2007 (5:18 am)
This tutorial here works pretty flawless and I used that one to build an A* purely in TorqueScript for my game SuperMaze. You can even enhance this stuff by adding influence maps (weight points for nodes in the navmesh which are taken into account when doing the pathfinding, like for example having a "death" map, places (=nodes) where many bots died will be taken less often). All this fancy stuff can be done with A* and influence maps.
Torque Owner Kevin Summers
Let's say for example you have a busy city in your game with lots of intersections.
You of course have paths that run down the streets, but what do you do at the
intersections?
One idea that I had was only have the paths go down the street from one corner
to the next, but not cross the intersection. At the intersection the bot can look up
a list of paths and can see the other paths that lead straight, left, or right. If the
bot isn't going anyplace in particular, it can pick it's next path at random. If it's
got a particular destination it could use some sort of algorythm to tell it which way
to go.
I'm planning to use something like this for townspeople walking around doing their
normal daily activities. So that we don't have everyone walking in a straight line down
the middle of the road I'm planning on putting multiple paths in each direction down a
street to give the appearance of a more natural flow of people.
Of course the more of this type of stuff I add to this game, the more likely it is that it
will take me 10 years to get it ready to release. :-(