Wandering AI
by Justin Morris · in Technical Issues · 08/19/2002 (5:30 am) · 9 replies
I dont know if this has been implemented in any games yet, but i just had what seems to be a really cool idea.
heres how it goes, set up a path of waypoints for your bot to follow and move the waypoints arround randomly but slowly, this way the bot kinda wanders arround from waypoint to waypoint with no sense of needing to get to an actual place. I think that method will be ideal for stupid Ai such as wild animals and what not, or, you could improve upon the above to make it work for smart bots like people, by setting up a start point and a finish point that are static, then putting in the dynamic waypoints inbetween so there is like a path that the ai follows to go some where, but it doesnt take the same path twice, that would be good for a bot like a paranoid travelling merchant that has to commute between 2 places regularly but is paranoid he might be attacked/followed.
A year or so ago i created another form of wandering AI, that didnt use a path at all, how it worked was a set of random numbers were generated:
1) direction
2) distance
3) speed
then a waypoint was set for the bot, it travelled there then more numbers were generated... it was pretty cool to watch somthing i made move arround on its own =) but the code was very primitive and would lead the bot off the map at times.
with improvements to the above it could be a very realistic form of moving your bots arround... like set up zones that the bot thinks of as safe areas, and others that are hostile, and others that are unknown, then just run checks on the waypoints as they are generated so that the bot doesnt run off the map or into objects, what would be really cool, is if there is a object in the bots path, a beizier curve is created in the path moving arround the object.
well, tell me what ya think of my idea
TTYL
heres how it goes, set up a path of waypoints for your bot to follow and move the waypoints arround randomly but slowly, this way the bot kinda wanders arround from waypoint to waypoint with no sense of needing to get to an actual place. I think that method will be ideal for stupid Ai such as wild animals and what not, or, you could improve upon the above to make it work for smart bots like people, by setting up a start point and a finish point that are static, then putting in the dynamic waypoints inbetween so there is like a path that the ai follows to go some where, but it doesnt take the same path twice, that would be good for a bot like a paranoid travelling merchant that has to commute between 2 places regularly but is paranoid he might be attacked/followed.
A year or so ago i created another form of wandering AI, that didnt use a path at all, how it worked was a set of random numbers were generated:
1) direction
2) distance
3) speed
then a waypoint was set for the bot, it travelled there then more numbers were generated... it was pretty cool to watch somthing i made move arround on its own =) but the code was very primitive and would lead the bot off the map at times.
with improvements to the above it could be a very realistic form of moving your bots arround... like set up zones that the bot thinks of as safe areas, and others that are hostile, and others that are unknown, then just run checks on the waypoints as they are generated so that the bot doesnt run off the map or into objects, what would be really cool, is if there is a object in the bots path, a beizier curve is created in the path moving arround the object.
well, tell me what ya think of my idea
TTYL
About the author
#2
i like your older wandering AI though. very simple. does it work in torque?
03/30/2005 (7:45 pm)
I've wanted aimlessly wandering AI, not sure if I'd use waypoints how your suggesting though.. my main concern.. waypoints getting stuck in terrain or buildings or places they cant really go... hmmmi like your older wandering AI though. very simple. does it work in torque?
#3
function setTaxiDes()
{
%taxiX = getRandom(-600,60); //keep it on the map
%taxiY = getRandom(-600,120);
taxi.setMoveDestination(%taxiX SPC %taxiY SPC 0);
schedule(18000,0,setTaxiDes);
}
03/30/2005 (8:10 pm)
I use this to move a bot called taxi. Crude, but it looks okay. function setTaxiDes()
{
%taxiX = getRandom(-600,60); //keep it on the map
%taxiY = getRandom(-600,120);
taxi.setMoveDestination(%taxiX SPC %taxiY SPC 0);
schedule(18000,0,setTaxiDes);
}
#4
By placing your wandering bot spawns cleverly around your map, you can get the bots to wander pretty much anywhere you like and get them to cross into other bot areas(overlap) which can lead to a percieved "team search" by a few bots wandering around the same area.
03/30/2005 (8:13 pm)
Wandering bots are pretty much the easiest ones to do(after pathed bots). Best way to keep them on the map is to limit their area via spawnpoint. Whenever you are ready to update the bots speed, direction, distance, you first run a check on how far away from your original spawnpoint you are. If(toFarAway == true){ head towards home for a while }.By placing your wandering bot spawns cleverly around your map, you can get the bots to wander pretty much anywhere you like and get them to cross into other bot areas(overlap) which can lead to a percieved "team search" by a few bots wandering around the same area.
#5
and in OnReachDestination, have the AI check whatever else you need checked. If all is well, schedule another wander.
If the location is blocked, AIPlayer is autmatically stopped and put into a stopped mode.
If OnStuck or OnMoveStuck is broken in your version, then you may need to fix that (we had an issue).
Make the same calls in OnStuck as in OnReachDestination for this (wrap it up in a function to make that easier).
if you want them to wander further or have areas that they may wander to and around, then you can set a node as a home node,
and have that AI occasionally change home nodes
06/16/2005 (9:37 am)
I think it may be better to use a waypoint and make a function that will do something like:AIPlayer::wander(%this, %rangeX, %rangeY)
{
// %rangeX & %rangeY set the maximum range that the AIAplyer will wander from
// the node you can easily set this up as passed in values to make it different for
// every type of bot that you may have (like scouts, sentry, or animals).
%locX = getWord(%waypoint.getTransform(), 0);
%locY = getWord(%waypoint.getTransform(), 1);
%newX = (%locX - %rangeX) + (getRandom() * %rangeX * 2);
%newY = (%locY - %rangeY) + (getRandom() * %rangeY * 2);
// this is obviously for AIPlayers that are bound by gravity. Flying types may do something similar to the X & Y locations above
%newZ = getTerrainHeight(%newX SPC %newY) + 1.0; // + 1.0 can prevent terrain vs bbox issues
%this.moveToDestination(%newX SPC %newY SPC %newZ);
}and in OnReachDestination, have the AI check whatever else you need checked. If all is well, schedule another wander.
If the location is blocked, AIPlayer is autmatically stopped and put into a stopped mode.
If OnStuck or OnMoveStuck is broken in your version, then you may need to fix that (we had an issue).
Make the same calls in OnStuck as in OnReachDestination for this (wrap it up in a function to make that easier).
if you want them to wander further or have areas that they may wander to and around, then you can set a node as a home node,
and have that AI occasionally change home nodes
#6
Now, to do something similar in a game could be usefull. All you'd really have to do if you predefined the waypoints was add an amount (in terms of distance) that the bot could "roam". You could also do random waypoints in some predefined area, but the problem is that you most likely won't get a useful path. It could turn out to be a tight circle or any number of other useless things.
One variation that might be more usefull is the define on the starting and end points of the path and let the points in between be determined on a somewhat random basis.
An obvious application for such a bot is in a RTS or other game type where resource gathering is important. One could define a peasant bot (ala warcraft) that wandered somewhat randomly to find resources like mines, trees, whatever. Then that peasant could either inform the player, or dispatch some minions to collect the resource.
06/20/2005 (5:46 am)
Well, in scientific computing we use a method called Monte-Carlo simulation to add variability. It essentially uses statistics and other models for the variables in a physical system. You would then take thousands and thousands of values from each variable's model and then determine for each set of values how the entire physical system behaves.Now, to do something similar in a game could be usefull. All you'd really have to do if you predefined the waypoints was add an amount (in terms of distance) that the bot could "roam". You could also do random waypoints in some predefined area, but the problem is that you most likely won't get a useful path. It could turn out to be a tight circle or any number of other useless things.
One variation that might be more usefull is the define on the starting and end points of the path and let the points in between be determined on a somewhat random basis.
An obvious application for such a bot is in a RTS or other game type where resource gathering is important. One could define a peasant bot (ala warcraft) that wandered somewhat randomly to find resources like mines, trees, whatever. Then that peasant could either inform the player, or dispatch some minions to collect the resource.
#7
07/18/2005 (5:22 pm)
I need a wonder script for my monsters in my MMO (they don't attack) so which one do i use and how do i implement it?!
#8
07/23/2005 (6:21 pm)
I need wondering AI for my monster soon! PLEASE HELP i would use that taxi thing but i don't know where to put it and i don't want the monsters wandering into the town?
#9
A simple way would be to just create spawn locations,
keep this waypoint value, and do the wander as I posted, keeping the %rangeX and %rangeY values low enough that it never could go into your town.
Use OnReachDestination to know when its done going there, and call or schedule a call to wander again.
-----
What I used was a script to create a grid of nodes all around a mission (about 80 nodes in all).
Then I created a test AI bot to run at high speeds from each node to all surrounding nodes to see if they could actually get there, and had it automatically compile a list of the nodes that the bot could reach and added it to a string array in the dynamic fields of each node called connectTo. For example, if I got the node object for node #10, its connectTo value might be something like: "1 2 3 9 11", which means that it can actually run from node 10, to each of these other nodes.
If the string was empty, then it couldn't go anywhere and was locked in an object or an otherwise immobile location. Essentially, making it a non-valid location.
I would randomly place bots at each of these validated locations and set them to an idle state, with randomly timed out wander actions.
The wander action was similar to my post above (June 16).
you could also add a field that says something like: validTeams = "1 5 8", where 1, 5, & 8 are teams that can wander to this location (bot townies can go in town, but not creatures). Set a value to test against in the datablock like team = 1.
Test the node before placing or moving AI to this location as a new home to see if its valid for this bot.
The node grid with a list allows me to find a path quickly from one location on the map to another and know that the AI can make it there. It also gives me a large number of optional locations to randomly place bots.
I would also create a random "findNewHome" action, where he may find a new node, validate, then create a new path of nodes to the destination.
Over busy these days, but I hope I can post script chunks to do some of this soon and hopefully clarify a little more in doing so. But I hope this gives you some direction. It does seem complicated, and is generically stated for now, but you can easily just take the parts you need and make the AI as complicated as you need it to be.
07/28/2005 (12:37 pm)
Tim:A simple way would be to just create spawn locations,
keep this waypoint value, and do the wander as I posted, keeping the %rangeX and %rangeY values low enough that it never could go into your town.
Use OnReachDestination to know when its done going there, and call or schedule a call to wander again.
-----
What I used was a script to create a grid of nodes all around a mission (about 80 nodes in all).
Then I created a test AI bot to run at high speeds from each node to all surrounding nodes to see if they could actually get there, and had it automatically compile a list of the nodes that the bot could reach and added it to a string array in the dynamic fields of each node called connectTo. For example, if I got the node object for node #10, its connectTo value might be something like: "1 2 3 9 11", which means that it can actually run from node 10, to each of these other nodes.
If the string was empty, then it couldn't go anywhere and was locked in an object or an otherwise immobile location. Essentially, making it a non-valid location.
I would randomly place bots at each of these validated locations and set them to an idle state, with randomly timed out wander actions.
The wander action was similar to my post above (June 16).
you could also add a field that says something like: validTeams = "1 5 8", where 1, 5, & 8 are teams that can wander to this location (bot townies can go in town, but not creatures). Set a value to test against in the datablock like team = 1.
Test the node before placing or moving AI to this location as a new home to see if its valid for this bot.
The node grid with a list allows me to find a path quickly from one location on the map to another and know that the AI can make it there. It also gives me a large number of optional locations to randomly place bots.
I would also create a random "findNewHome" action, where he may find a new node, validate, then create a new path of nodes to the destination.
Over busy these days, but I hope I can post script chunks to do some of this soon and hopefully clarify a little more in doing so. But I hope this gives you some direction. It does seem complicated, and is generically stated for now, but you can easily just take the parts you need and make the AI as complicated as you need it to be.
Cobra