Game Development Community

dev|Pro Game Development Curriculum

AIWheeledVehicle2

by Brian McGavin · 10/16/2005 (12:32 am) · 35 comments

Download Code File

AIWheeled vehicle was an outstanding resource. I have done some work to improve the steering and speed control. In this resource I have made a new class called AIWheeledVehicle2, and I have added an example mission that will make a robot car that drives around the starter.racing track.

This resource is made for Torque v1.4 and works with starter.racing example
You need to do the following once you download the zip file.

1. Add AIWheeledVehicle2.h and AIWheeledVehicle2.cc to your project.
2. Add carbot.cs to your server script folder
3. Add robotracing.mis to your data/missions folder
4. Modify the file game.cs in your server script folder
add the line
exec("./carbot.cs");
after the line
exec("./checkpoint.cs");

add the lines in 'function startGame()'
//Robot car
$Bot1 = CreateAIWheeledVehicle2("Herbie","CarPath",pickSpawnPoint());
MissionCleanup.Add($Bot1);
echo("Bot id: " @ $Bot1);

after
if ($Game::Running) {
error("startGame: End the game first!");
return;
}

add the lines in the 'function startRace()'

$Bot1.followPath("CarPath", -1);
$Bot1.lap = -1;
$Bot1.nextCheck = 1;

before the lines
// Start the game timer
// if ($Game::Duration)
// $Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" );
$Game::Running = true;

$Game::Running = true;

5. Run the starter.racing game and choose robotracing.mis


How it works.
You need to create a path for the vehicle to follow in your mission. You also need to add a dynamic field 'speed' at each path point. You will want to set smaller speed values for sharp turns and bigger ones for straightways. It will require some trial and error to tweak it right. The path you create needs to be a drivable path.

The vehicle will try to follow the 'racing line' you draw. The farther the vehicle gets from the racing line the sharper the turn.

About the author

Recent Blogs

Page «Previous 1 2
#1
10/16/2005 (1:28 am)
where is the link to the zip file?
#2
10/16/2005 (6:38 am)
I guess it got lost some how. It should be there now
#3
10/16/2005 (10:32 am)
Yay the resources are back!!!! oh and this will be helpful I say this as my ai player drives around in circles.
#4
10/18/2005 (3:36 am)
I'm totally new to this, so please be gentle!
if someone could help me out, I will be forever grateful

I've followed this all through, but how do I connect a vehicle to the path created??
#5
10/18/2005 (8:15 am)
@540 media

In game.cs(in the sever directory) these lines set the path.

$Bot1 = CreateAIWheeledVehicle2("Herbie","CarPath",pickSpawnPoint());
$Bot1.followPath("CarPath", -1);

Change "CarPath" to the name of your path.
#6
10/19/2005 (3:01 am)
@Brian

I did that but still no luck,
no vehicle is spawning to connect to the path in the first place
#7
10/19/2005 (5:33 am)
@540 media
What does your console output say when you start the mission?
#8
11/09/2005 (4:00 am)
#9
11/28/2005 (3:32 pm)
@Juan
Sorry to take so long. What exactly do you mean by SetMoveSpeed? Do you want a scriptable call? Are trying to set the speed for the next node? It wouldn't be to hard to a scriptable call to set the speed of a desired node. Basically the way the code works is if your vehicle is less then the target. It will apply full throttle until it reaches that speed. I sometimes use speeds of 1000 so that my vehicle will try to go as fast as possible.
#10
11/29/2005 (1:33 am)
#11
11/29/2005 (9:54 am)
@Juan
Don't worry your english is fine. I understand now what you are trying to do. That is pretty cool. I wrote a game once that was connected to an exercise bike.

I don't think it would be that hard to add what you want. I will try to add a scriptable function call SetDesiredVehicleSpeed(). I will send it to your email listed in your profile.

Good luck
Brian
#12
11/30/2005 (12:44 am)
.
#13
12/02/2005 (1:55 pm)
Hi. This resource is exactly what I needed. However I have one big problem. After setting this resource up TGE crash. I am sure that problem is not in this resource.

I didn't follow this resource exactly as explained becouase I am trying to add this resource to my existing project. Everything compiles fine, I add scripts, link to my shape and just when mission is about to start TGE freeze & crash.

******LAST FEW LINES FROM CONSOLE LOG**********



*** New Mission: GameOne/data/missions/TutorialMission.mis
*** Phase 1: Download Datablocks & Targets
Mapping string: MissionStartPhase1Ack to index: 0
Warning: shape GameOne/data/shapes/3dtorquelogo/torque_logo.dts collision detail 1 (Collision-1) bounds exceed that of shape.
Warning: shape GameOne/data/shapes/car/car.dts collision detail 1 (Collision-5) bounds exceed that of shape.
Warning: shape GameOne/data/shapes/car2/car.dts collision detail 1 (Collision-5) bounds exceed that of shape.
Mapping string: MissionStartPhase2 to index: 9
*** Phase 2: Download Ghost Objects
Mapping string: MissionStartPhase2Ack to index: 1
Ghost Always objects received.
Mapping string: MissionStartPhase3 to index: 10
Client Replication Startup has Happened!
fxFoliageReplicator - Lev: 2 PotNodes: 21 Used: 18 Objs: 1091 Time: 0.0100s.
fxFoliageReplicator - Approx. 0.12Mb allocated.
fxFoliageReplicator - Client Foliage Replication Startup is complete.
*** Phase 3: Mission Lighting
Successfully loaded mission lighting file: 'GameOne/data/missions/TutorialMission_a790d1e2.ml'
Mission lighting done
Mapping string: MissionStartPhase3Ack to index: 2
Set::getObject index out of range.
Bot id: 1378
followPath()

END OF CONSOLE LOG
********************************************


***************
OK IT WAS MY ERROR!!!

One of the marker wasn't attached to path...stupid error :)

Thanks!
#14
12/03/2005 (10:19 am)
@Denis
Are you still having trouble or did you fix the error?

@Juan
I sent you an email with the changes. Hopefully it will work for you

Brian
#15
12/03/2005 (10:43 am)
I solved it Brian, Thanks for asking. One of the path markers wasn't grouped under path and that produce crash.

Now I am strugling with physics (with Rigid Shape precisely), but that's another problem.

Thanks for the resource, I have 4 cars all following path perfectly, now I have to implement somekind of obstacle avoiding scheme.
#16
12/03/2005 (12:17 pm)
@Denis

I had an idea about obstacle avoidance. You could make multiple paths and if you path was blocked switch to another path. Of course there would still be special cases like when you got stuck.

Brian
#17
12/03/2005 (12:32 pm)
Acctualy I was thinking of something else. Something like moving vehicle slightly to the left or right (random) becouase I usually need this when bot1 car get's in front of bot2 car...or vice versa so I can't really know where that is going to happend.

Right now I have 4 car's running the race and your resource works great (one of that car is me ;) )

I was very carefull while designing the prototype level so that bots doesn't have too much space for error or stucking. (but this had to be tested) ;)

I will email you or post here if I found anything interest.
#18
12/07/2005 (8:55 pm)
Brian, my solution of obstacle avoidance doesn't work. I will try your idea, just have to create smaller race track for testing. Can I email you if I have some questions?
#19
12/15/2005 (7:10 am)
#20
12/16/2005 (8:31 am)
Unfortunatly I don't have time right now...my day job is only thing I can work in this time of year.
After New Year I will have more time and hopefully more results ;)
Page «Previous 1 2