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
Page«First 1 2 3 Next»
#41
11/28/2006 (10:55 pm)
Strangely enough, the function is in the bot.cs file that you have clearly indicated should be included in the project. Sorry it has been a long day..
#42
12/30/2006 (9:40 am)
Trying in 1.5, thought I'd point out that the changes in vehicle.cc/h are already present :-)

Edit: Doh! and furthermore, aiwheeledvehicle.cc/h are also already present in engine/game, and so if you stick the downloaded ones under engine/game/vehicle it won't build!

All this convenience is very confusing! :-)
#43
02/05/2009 (2:39 am)
I have implemented this into TGE 1.5.2 and as Lee pointed out, all the engine changes have already been done, and so i just added bot.cs, and exec it in game.cs

I have one problem, the car/bot spawns on my first path marker, but doesn't move anywhere...

From Max

Ps I am actually using this with starter.fps, but have followed the changes in my own resource called Drivable cars in starter.fps and then just added the things from this resource, and my result is what i explained above :(
#44
02/05/2009 (2:47 am)
@Max: do they have a destination?

Are you using a script IDE like Torsion? That's invaluable for sorting out problems like this. It's fairly certain that the problem is not in code, but in script.

Also, try going into the Mission Editor and screwing around with the ai vehicle. Pick it up and drop it. If it starts moving after that, you know the problem does indeed lie in code, a physics issue or some such.
#45
02/05/2009 (11:20 pm)
@lee

i tried picking up the car, and droping, but it doesn't start driving after it has been droped.

I also use jEdit as my IDE. I'll just run through my script to make sure it looks right :)

from Max
#46
02/05/2009 (11:42 pm)
Try telling it to go somewhere in the console, while running the game ;-). That'll show you what you need to do.
Page«First 1 2 3 Next»