Game Development Community

dev|Pro Game Development Curriculum

Simple AI Vehicle AIWheeledVehicle

by Brian Richardson · 08/16/2004 (10:19 pm) · 46 comments

Download Code File

This would not be possible without Badguy's getSteeringAngle function!

Code archive mirrored here:
http://knowhere.net/gg/aiwheeledvehicle.zip

Steps:

1. Add AIWheeledVehicle.cc and AIWheeledVehicle.h to your torque project.
Copy the files to the engine/game/vehicle directory.

2. In Vehicle.h:

After:
void renderMountedImage(SceneState *state, ShapeImageRenderImage *image);

But before:
public:

Add this line:

virtual bool getAIMove(Move* move);

The full block should look like this:
void renderMountedImage(SceneState *state, ShapeImageRenderImage *image);

	virtual bool getAIMove(Move* move);
public:

3. In Vehicle.cc:

In Vehicle::ProcessTick after:
Parent::ProcessTick(move);


Add (this is equivalent to the code in player.cc):
// If we're not being controlled by a client, let the
   // AI sub-module get a chance at producing a move.
   Move aiMove(NullMove);
   if (!move && isServerObject() && getAIMove(&aiMove))
      move = &aiMove;


At the end of the file, add this block:
//
// AI stuff
bool Vehicle::getAIMove(Move* move)
{
	return false;
}

4. Recompile the engine.

5. Copy the bot.cs into the server/scripts/ directory of your game.
Add this line to server/scripts/game.cs:
exec("./bot.cs");

6. Finally, to create the bot, add this line to your onMissionLoaded function
in server/scripts/game.cs:

$Bot = CreateAIWheeledVehicle("MasterBlaster", "MissionGroup/TrackPath");

TrackPath is the name of a path you've created with the mission editor. See the
bot path finding tutorial listed in the link above for info on how to create that.

Hope this helps!
Brian Richardson
#21
04/15/2005 (1:32 am)
#22
04/15/2005 (1:06 pm)
@Juan:

Here are my hints on that one:

1. Look at WheeledVehicle::renderImage, you can see that it renders each wheels shapeImage manually.

2. You'll have to override Shapebase::renderShadow to render your wheels shadow into the shadow object.

@Lee:

I haven't had a chance to check that out. Based on other similiar issues I've read, there may need to be more info ghosted across the pipe. Or something may need to be reinited after receiving an update.
#23
04/18/2005 (5:01 am)
#24
04/19/2005 (12:54 am)
#25
04/27/2005 (3:52 am)
#26
10/19/2005 (2:35 am)
I'm a newbie so if anyone can help me with this it would be great

I've followed everything to the letter but I dont have any bot following the path
what am I doing wrong??

I've followed the example at http://www.codesampler.com/torque.htm and get get the bot to work
but as soon as I try this one with the racing start kit - nothing?

please someone help
#27
10/19/2005 (5:11 pm)
Checkout the console log, are there any errors. You will have to provide more information othervise it's hard to help.
#28
10/20/2005 (2:17 am)
problem solved
#29
11/14/2005 (8:50 am)
can this resource be used on fps?
thanks
#30
11/14/2005 (9:38 am)
Yup!
#31
11/16/2005 (7:00 am)
@Brian thanks I've managed to add it and it works. However, when I add an object through the console it doesn't get added to other connected clients. This is how i add it

$Bot = CreateAIWheeledVehicle("MasterBlaster", $Path);

Is there away to force it to be added to all clients?

The other thing I noticed is that the constructor "AIWheeledVehicle::AIWheeledVehicle() :WheeledVehicle()" gets called twice, can somebody shed a light on this.

Thanks
#32
11/16/2005 (9:09 am)
It should ghost to all clients after it's been added. I'm not sure what could be wrong there.

The contructor gets called twice: once for the server version of the object and once for the client version of the object.
#33
11/24/2005 (2:14 pm)
AWESOME! Thats exactly what I was looking for! :D
Works Fine!
#34
11/24/2005 (2:23 pm)
Portalguy, its not ghosting on the other clients because the Server is the one supposed to create the bots. The way you are doing (calling the creation function on the console) only that client has that object.
#35
12/17/2005 (8:00 am)
I am just trying to figure out how this class works, can anyone help me to explain how the getsteeringangle() function, my math is really bad. thanks a lot!
#36
03/27/2006 (7:07 pm)
Looks like this code was added to the engine at least by 1.4. The main thing is that it doesn't seem to incorporate XoCluTch's improvements. Also, the aiWheeledVehicle files are in engine/game/ rather than engine/game/vehicles
#37
03/29/2006 (1:18 pm)
I have read all the threads. Am I understanding correctly that the only way to get an AI wheeled vehicle to follow a prodetermined path is to modify the .cc code mentioned above. No script only solutions for allowing a wheeled vechicle to attach to a user defined path and have it follow as a certain speed? -Greg
#38
06/21/2006 (6:23 am)
I've got a problem...
When added the new game.cs, the checkpoints in starter.racing don't work.
Help me!!!
#39
08/24/2006 (11:25 pm)
hi Biran

AIwheeledvehicle is very usefull for my game, but when i use the pathmarker to spawn the vehicle on the start node of the path, i got a error "followpath failed- Bad path", when i use the same path for AIplayer the aiplayer is moving in the path,

what is error in the aiwheeledvehicle code, Help me!!
#40
11/28/2006 (10:09 pm)
Thansk for the guide, I have only one noob question, where is the CreateAIWheeledVehicle function defined?