Game Development Community

Scripting Vehicle Bots

by James Brady · in Torque Game Engine · 08/09/2004 (3:04 am) · 12 replies

I'm trying to make a vehicle bot (with scripting if that's possible).

I used the tutorials at

http://www.codesampler.com/torque.htm

which are fantastic - the closest example is the 'Bot Path-Finding' tutorial, but that assumes that the bot will be like the player (and uses the same model).

How could I make another model (eg the buggy) be the bot and follow a path ?

The closest I got was to copy player.cs to (say) botPlayer.cs and change the shapeFile there to point to buggy.dts - that way I have a different player and bot (but its not a good solution as the bot is really just a 'player' disguised as a buggy!).

I'd really appreciate some help on this one. Is there already a tutorial on scripting a vehicle bot ?

Thanks for any tips/pointers.

#1
08/09/2004 (5:57 am)
Here's a thread about making normal AIPlayer's better drivers:

http://www.garagegames.com/mg/forums/result.thread.php?qt=5091

I've also got a simplified version of the code in that thread called AIWheeledVehicle which doesn't require the AIPlayer to be in the loop. I'll clean it up and post it as a resource tonight and put a link here.

Brian
#2
08/09/2004 (2:15 pm)
Here's the link to the resource:

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6222

I just submitted it, so you may have to wait for it to get approved.

Thanks,
Brian
#3
08/10/2004 (7:13 am)
Brian,

What would it take to mount a weapon (or turret) on this vehicle and have it fire at (or near) the player ?

Following the ideas in the 'Weapons' tutorial of codesamples, my attempt to mount the rocket launcher was to add 3 lines to buggy.cs (about line 167) in the onAdd function as follows:

function WheeledVehicleData::onAdd( %this, %obj )
{
parent::onAdd( %this, %obj );
//to add a rocket launcher to the buggy
%obj.mountImage( RocketLauncherImage, 0 );
%obj.setImageAmmo( 0, 1 );
...

}

..but I didnt see the rocket launcher on the buggy. Besides, this would'nt get the rocketlauncher using AI to fire at the player....

Thanks for any tips (or pointers to relevant resources!)

James.
#4
08/10/2004 (10:54 am)
@James

Have you looked inside the buggy? It's possible it's mounting to the driver's seat or the origin, and you just can't see it.

As for making it actually shoot the rocket launcher, I think you're going to have some c++ to write.
#5
08/10/2004 (2:27 pm)
You are right Andrew - the launcher is hidden inside the buggy! (Any tips for moving it relative to the buggy ?)

I just got the engine and love it. I'm looking forward to working with the code and Brian's resource above was a great start!

About getting enemy bots to fire at the player - surely there is some resource somewhere on that one ?

I did come across some bot tutorials at:

http://tork.beffy.de/modules.php?op=modload&name=ToRKTutorials&file=index

which look very promising but its not clear (to me) how to integrate them... would be great if there was a resource here at gg to explain how to do so...

Any other pointers / ideas ? Thanks.
#6
08/10/2004 (8:42 pm)
You can choose where it's mounted by using mount points in your models. Right now you have your weapon mounting to mount0, so first check to be sure you 1) want it to be mounted to that mount point, 2) that "mount0" (in your buggy model) exists and it pretty close to where you want your weapon to show up (otherwise, if you don't have a mount0, the engine just places it at the buggy object's center) and 3) that you have a "mountPoint" object on your waepon and it matches where you want the weapon to attach to mount0.

If you don't want to use mount0, you can create a number of other mounts in the format of mount# (e.g. mount1, mount2, mount3, etc.). I believe there's a max number of mount points per object (maybe eight?). To mount the waepon to a different mount number just change the second variable in your mountimage call to the mount number you want to use. For example, if I wanted to mount to mount1, I'd call %obj.mountImage( RocketLauncherImage, 1 );

That should do it . . . oh, you can also change the mount number in the weapon image's datablock description. It's something like "mount = 0;" by default. I don't recall if this makes a difference when you explicitly choose the mount number in the mountImage call . . .

Hope that all makes some sense and helps ya out some . . . if you have any other questions about mount points, let me know . . . I use them extensively in my project ; )

Ciao,
-rob
#7
08/11/2004 (3:34 am)
Probably the best way to get AI controlled shooting with your car is to use
Paul Dana's AI Turret resource here:

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4116
#8
08/11/2004 (6:45 am)
Robert - thanks for the tips on mount points - very helpful.
Brian - that is exactly the resource I was looking for. Perfect.

Below is a 1.2.x update to Paul Dana's AI Turret resource (from Brian Howard). It solved the compilation errors I ran in to:

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5345

Thanks again,

James.
#9
08/12/2004 (4:21 am)
I got that compild and the AI turret tracks the player when within the specified radius - it then calls :

function AITurretData::fireGun(%this,%turret)
{
// fire gun
%turret.fire(0);

echo("FIRING NOW: at " @ $Sim::Time);

// setup next fire time
%this.setupNextFire(%turret,%this.fireRate,%this.fireRateVariance);
}

periodically as it should..

The problem is that, although %turret.fire(0) is called, I don't see any projectile leaving the turret - there are also no errors in the console...

Anyone know how to get the turret to fire a projectile and cause damage ?
#10
08/12/2004 (8:36 am)
Does it have a weapon mounted on it? You could also just spawn the projectile directly... ie, call new Projectile() instead of calling fire.
#11
08/12/2004 (9:40 am)
Thanks Ben, I just found the reason - I missed the changes of that patch to the shapeBase.cs file - when I added those changes then the turret fires!
#12
08/12/2004 (2:37 pm)
Heheh... Whoops!