Game Development Community

dev|Pro Game Development Curriculum

Vehicles Galore

by Tom Feni · 10/14/2004 (12:59 pm) · 47 comments

4 vehicles to use as learning tools.
included:
Dts shapes for vehicles, scripts for the vehicles, milkshape files for all vehicles. all the textures for the vehicles.

Vehicle spawners. 3 vehicle spawns for the hover, car, and tank.. didnt get the plane one done but its fairly simple to see how I did it.

Its mainly a way to see how the script works and to fine tune your own shapes..

all of these work great out of the box.. none of them will fly thru the terrain and will not crash the game.. :)

so if you do fiddle try to do so slowly so you dont get things out of whack.. :)

Now you will want to take all the scripts and add them to your scripts folder in server..
ie/ server/scripts

then open game.cs and add
exec("./tooncar.cs");
   exec("./toontank.cs");
   exec("./hovervehicle.cs");
   exec("./flyer.cs");
   exec("./flyervehicle.cs");
   exec("./vehiclespawn.cs");

with the other exec's

now add all the shapes to your client/shapes folder...
now when you open your editor all the vehicles should show up in the editor.. all save the hover will spawn by clicking on the vehicles/ shape name..

for some reason the hover wont load normally.. use the vehicle spawn points which are also loaded into the editor under vehspawns...

play around and if you have any questions let me know.. :)


oh and hey, you might need the link:

New Vehicle Zip


* ok had some probs with the server.. feel bad about it so going to upload my recent vehicle stuff.. so there are alot of things in semi-finished state.. all as-is...
Finally.. its fixed..

enjoy.. :)



ok reuploaded the files as of 4-10-2006
Page «Previous 1 2 3 Last »
#1
10/13/2004 (7:16 pm)
I will add pics soon
#2
10/13/2004 (7:50 pm)
ok pic of all the goods..

home.comcast.net/~r.fenimore/vehicles1.jpg
#3
10/13/2004 (8:11 pm)
Nevermind..
better code right below mine.. :)
#4
10/14/2004 (1:57 pm)
I have never understood why everyone thinks it's neccesary to name every vehicle you could possibly collide with as a possible collision in their on collision function. First of all, if there is no vehicle there, you cannot collide with it. Secondly, if there is a vehicle there, it will 99.9999999999% of the time be one of the exact vehicles you named. So unless you know exactly why you would need to specify cartain vehicles then you only need to check for vehicle collision using these two parameters....


%obj.mountVehicle && %col.mountable

If the player can mount vehicles, and the object you collided with is mountable then get on. If you want a vehicle to not be mountable by the player, then set the mountable value to false.

function Armor::onCollision(%this, %obj, %col)
{
	if(%obj.getState() $= "Dead"){return;}
 
	if(%col.getClassName() $= "Item"){%obj.pickup(%col); return;}
 
	if(%obj.mountVehicle && %col.mountable)
	{
		%col.mountObject(%obj, 0);
	}
}
#5
10/14/2004 (5:54 pm)
sweet thanks.. :)
#6
10/14/2004 (6:24 pm)
Yep yours is much better then mine.. :)
#7
10/14/2004 (7:26 pm)
Tom, if you are interested, I looked at your code in your source files and see quite a few areas you could clean up. I'd be glad to edit them and send them back if you want to compare. In some cases the code would be gone, and in others it would be altered, then you can email me if you have questions as to why I did what I did.
#8
10/14/2004 (8:38 pm)
Well to be frank that is why I posted all this to begin with.. :)
We are a communtiy.. :) so this is a community resource.. I would enjoy seeing how you would do it.. and maybe merge them together and I can update the url so it has the recent changes..
I will keep updating the files as they evolve.. :)

I forgot that the tank code has my ballammoprojectile class for the ammo.. so if you want change it to the crossbowammo projectile.. (i forget what its called) and you will shoot arrows.. I couldnt get it all in one script before I released it all.. I have 100's of mini projects going at any given time so I dont spend too much time on one thing.. :) Problem with being a multi tasker.. I get to stretched out.. :) oh well.. at least I only have to rely on myself as far as the game goes.. but then it may take longer then I planned to finish.. :)

But keep adding suggestions and we can get this resource nailed down so people can get a jump on vehicles.. :)
#9
10/14/2004 (10:36 pm)
Good stuff, good stuff. Like seeing the teamwork, I'll be following this one.
#10
10/14/2004 (10:49 pm)
Yup yup... I'll also be following and hopefully learn something.

Here's my first Question... in VehicleSpawn.cs can't we change the Itemdata of all the vehicles to something like this?

datablock ItemData(Spawner)
{

   // Mission editor category, this datablock will show up in the
   // specified category under the "shapes" root category.
   category = "Vehicle Spawners";

   // Basic Item properties
   mass = 1;
   friction = 1;
   elasticity = 0.3;

   // Dynamic properties defined by the scripts
   maxInventory = 0; // No pickup or throw

   lightType = "PulsingLight";
   lightColor = "0.8 0.4 0.3 1.0";
   lightTime = "2000";
   lightRadius = "15";

   isInvincible = true;

}

datablock ItemData(carSpawn:Spawner)
{
   shapeFile = "~/data/shapes/vehspawn/vehiclespawn.dts";
};


datablock ItemData(tankSpawn:Spawner)
{
   shapeFile = "~/data/shapes/vehspawn/vehiclespawn1.dts";
};

datablock ItemData(hoverSpawn:ItemData(tankSpawn:Spawner))
{
   shapeFile = "~/data/shapes/vehspawn/vehiclespawn2.dts";
};

I'm just trying to get my head around this...
Then another thing i've noticed is there is 2
tank::onAdd functions... Shouldn't the one be wheeledVehicle::onadd()?

function Tank::onAdd(%this,%obj)
{
  parent::onAdd(%this,%obj);
  %obj.mountImage(carbowimage,0);
  %obj.mountImage(carbow2image,1);
  %obj.setImageAmmo(0,1);
  %obj.setImageAmmo(1,1);
}
and

function Tank::onAdd(%this,%obj)
{
   // Setup the car with some defaults tires & springs
   for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
      %obj.setWheelTire(%i,defaultCarTire);
      %obj.setWheelSpring(%i,defaultCarSpring);
      %obj.setWheelPowered(%i,true);
   }
   
   // Steer front tires
   %obj.setWheelSteering(0,1);
   %obj.setWheelSteering(1,1);

   // Only power the two rear wheels...
   %obj.setWheelPowered(2,true);
   %obj.setWheelPowered(3,true);

   // energy
   %obj.setEnergyLevel(%this.MaxEnergy);
   %obj.setRechargeRate(%this.rechargeRate);
   
}
#11
10/15/2004 (8:42 am)
Burning, i think he made a whole new class together for the tanks.
#12
10/15/2004 (5:50 pm)
Yeah I condensed the onadd function and it works fine.. so I will fix that and add it to the resource soon.. when I get enough together.. for now you can combine the two onadds and it willw ork..
The vehicle spawn code I got form gamebeavers demo game.. I just added more vehicle types to it and made the new dts shapes to specify the spawn points..

I will add a flyer spawn dts also.. :)
#13
10/16/2004 (4:29 am)
Ok Tom, lets take this one function at a time so you wont get overwhelmed and you can see exactly how to fix the others...

In your vehicleSpawn.cs file, the last function is Let's start with that one. Below I have copy pasted that function without the code you already commented out, and I've altered it to a more efficient and cleaner state as well as corrected or removed the flawed logic.

function hoverSpawn::onCollision(%this,%obj,%col)
{
   // Gonzo -	Instead of checking to see if it is NOT dead, check to see if
   //		it is dead OR if it is mounted, if so then return.
   if( %col.getState() $= "Dead" || %col.isMounted() ) { return; }
   
   // Gonzo -	Since the below checks were called after your respawn, we can
   // 		now move it to here because it is safe to assume that all your
   //		criteria were met for needing a respawn.
   %obj.respawn();
   
   
   // Gonzo - 	%col.client.player == %col.  They are the same thing.
   //		%col will never be string equal to "" because if their player dies
   //		the %client.player variable is set to "0", therefore it will always
   //		return true and thus this check is useless.
   
    //if(%col.client.player$="")
      //return;
    //if(%col.client.player)
      //if(%col.client.player.isMounted())
         //return;

    %vehicle = new hoverVehicle()
    {
       dataBlock = hover;
    };
    MissionCleanup.add(%vehicle);
    // Gonzo - 	IMO you should always be in the habit of adding a new object to its
    //		assigned group BEFORE you begin to do any work or changes to it.  So
    //		I moved the above line to its new position.
    
    // Gonzo - 	These two should not be here because they need to be in the
    //		function Hover::onAdd(%this,%obj) which is called automatically 
    //		when the new Hover vehicle is created.  
    %vehicle.mountable = true;
    %vehicle.mountHide[0] = 1;
    
    
    // Gonzo -	This is already being set in function Hover::onAdd(%this,%obj) so it
    //		does not need to be done here.
    //%vehicle.setEnergyLevel(60);
    
    
    %vehicle.setTransform( %obj.getTransform() );
}


Make the requested changes and remove the commented code and you get a nice neat...

function hoverSpawn::onCollision(%this,%obj,%col)
{
	if( %col.getState() $= "Dead" || %col.isMounted() ) { return; }
 
	%obj.respawn();
	 
	%vehicle = new hoverVehicle()
	{
		dataBlock = hover;
	};
	MissionCleanup.add(%vehicle);
	 
	%vehicle.setTransform( %obj.getTransform() );
}


If your interested, I can show you some more.
#14
10/16/2004 (4:48 am)
Hmmmm, now that I take a look at that again(I'm picky about my code, lol) I see something that can be a little test for you or anyone else. The very first line of that function...

if( %col.getState() $= "Dead" || %col.isMounted() ) { return; }


has one flaw that would benifit nearly any game to have corrected. The code is just fine, but it's not quite good enough. Can you figure out what it is?
#15
10/17/2004 (2:16 am)
Looks good.. :)

I dont know alot about scripting yet, but someone else may see it..
If you want to clean up the scripting, that would be great. I can add it to the resource and reupload it to my server.. My email is R.Fenimore@comcast.net
I will update the vehicles later also.. so it continues to evolve and grow.. :)
#16
10/18/2004 (8:07 am)
Well assuming that you have "short circuit" evaluation of an 'or' function one thing to improve it would be to reverse the test.

if (%col.isMounted() || %col.getState() $= "Dead") {return;}

You are likely to be "mounted" on a vehicle a lot more than you are going to be "Dead" in game so testing the more likely true condition in an 'or' statement will make it "short-circuit" - you don't need to test the second condition if the first one is true so the 'or' code skips the test.

Most 'or' conditions that programmers usually write forget to put the most likely true candidate first.
#17
10/18/2004 (9:19 am)
An excellent point. Efficiency is always a top priority with me as well. A lot of programmers just see faster and faster PC's coming every day and think that it really doesn't matter much now. But I disagree, I think efficiency is paramount when dealing with scripted functions that run outside the engine so to speak.

However, I'm looking more for an addition to the statement that will solve what could be a messy situation.
#18
10/18/2004 (10:53 am)
%vehicle = new hoverVehicle()   {      dataBlock = hover;   };

could be
%vehicle = new hoverVehicle()   {      dataBlock = %block;   };

possibly?
#19
10/18/2004 (1:09 pm)
Well, for a little more structure, you just can't have too many parentheses :-)


if ((%col.isMounted()) || (%col.getState() $= "Dead")) {return;}
#20
10/19/2004 (1:58 am)
LOL, that's a good one. But no. What I was looking for was...

if (%col.getClassName() !$= "Player" || %col.isMounted() || %col.getState() $= "Dead") {return;}



The reason for this is you do not want objects like, thrown weapons or items, projectiles, or vehicles to set off a vehicle spawn. So a wise guy could throw a bunch of stuff or park a vehicle on one of the spawns and start filling the server, lol. The other way assumes every collider is to be treated and handled the same. They obviously cannot, so we really need to "short circuit" as David would say if we find out our collider is not a player.
Page «Previous 1 2 3 Last »