Game Development Community

Adding AI Player

by Ronald Andaya · in General Discussion · 08/07/2005 (11:24 pm) · 11 replies

I created a new mission and wanted to add my own AIPlayers to the game. My game is a mod of the fps.starter but for some reason the default AIplayer doesn't spawn into the game. In console I get an infinite number of erros saying "Unable to find object..." and the problem is from the aiplayer.cs. I guess it is trying to spawn the aiplayer but something is stopping it from doing so. Does anyone know how to load the aiplayer? And does anyone know how to create the paths that the aiplayer will follow.

#1
08/08/2005 (12:42 am)
What .exe are you useing? Did you compile the demo?Did you change anything?

Check this out for the pathfinding
http://www.codesampler.com/torque.htm
#2
08/08/2005 (10:19 am)
I created my own .exe just to add my own icon and name to it. Changes that I've made so far is the new mission, added weapons, added an interior instance, and that's it.
#3
08/08/2005 (10:32 am)
This is the error i get in the console.

MyGame\server\scripts\aiplayer.cs (236): Unkown command followpath.
#4
08/08/2005 (10:37 am)
How are you spawning the aiplayer? are you using spawnOnPath ?

or :

AIPlayer::spawn(...) ?

If you are alling spawnOnPath, are you providing a valid path ? Try calling it as Spawn instead.. or alternatively using hte AIGuard resource, which seems to be far more funcitonal and ready to go.
#5
08/08/2005 (11:04 am)
Ok I figured it out, in the aiplayer.cs I was implementing the paths created in the stronghold mission and not my own paths that had a different name in my mission. How do I add multiple aiplayers with different paths? Do I simply create other aiplayer scripts and have them follow their own path nodes?
#6
08/08/2005 (11:18 am)
Just call AIPlayer::spawnOnPath and feed it a different path. It will instantiate another aiplayer and seek it on whatever path you give it.
#7
08/08/2005 (11:50 pm)
How do you stop the AIPlayer from cycling back to the beginning of the path? I want them to stop at the last PathMarker.
#8
08/09/2005 (12:18 am)
You will need to make a new function very similar to the function AIPlayer::moveToNextNode but without the loopback to node 0.
#9
08/09/2005 (9:28 am)
@Ronald: You need to set the "targetNode" to the last node in the path. The default AIPlayer will keep going until it reaches the targetNode. When its not set, it keeps going forever. If it's set to a negative number, it'll go forever backwards through the list of path nodes.

This just just about the only part of the engine where I have hands-on experience. OTOH, it's also the area to which I've made changes, so I could be describing my script instead of the one that comes with starter.fps
#10
08/09/2005 (2:07 pm)
Ok, I'm kinda confused about the algorithm for followPath. Is targetNode the last node in the path? From followPath it calls the functions moveToNode...does it also call moveToNextNode? I'm asking this because I placed a couple echo("...") in the functions to see how the algorithm works and moveToNextNode is called, sometime after moveToNode, but function moveToNode never calls it explicitly. Also what does path.getCount() return...the number of the path, the number of the nodes in the path?

All of this comes from aiplayer.cs from starter.fps.
#11
08/09/2005 (3:39 pm)
Movetonext node is called by function DemoPlayer::onReachDestination, in it is see Mark is right about target node stoping the loop.