Game Development Community

Make 2 WheeledVehicle different?

by Dan - · in Torque Game Engine · 12/13/2003 (6:48 pm) · 7 replies

I am sure I don't understand the datablocks within the wheeledvechiles, but here is my problem:

datablock WheeledVehicleTire(DefaultCarTire)
{
  // Tires act as springs and generate lateral and longitudinal
   // forces to move the vehicle. These distortion/spring forces
   // are what convert wheel angular velocity into forces that
   // act on the rigid body.
   
   shapeFile = "~/data/shapes/car/wheel.dts";

I have 2 of these "WheeledVehicleTire" In one I have whats above. In the other I have shapeFile =

Both cars have the exact same wheels. It appears that you can't override the tires shapes likes this.

Also using the TribeIDE debugger they both are using the same WheeledVehicleData::onCollision

I know that both files are being used because the base body for each is correct (as defined in datablock WheeledVehicleData)

Is there an easy way to make 2 wheeled vehicles have different wheel shapes and different "onCollision" functions?

Thanks,

#1
12/13/2003 (7:10 pm)
Name it something else.
#2
12/13/2003 (8:07 pm)
The tires which get mounted to the vehicle are spicified in the vehicles ::onAdd function, the default looks something like this:

for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,DefaultCarTire);
%obj.setWheelSpring(%i,DefaultCarSpring);
}

What you need to do is change it to something alonge these lines:

%obj.setWheelTire(3,MyTireName);
%obj.setWheelSpring(3,DefaultCarSpring);


%obj.setWheelTire(2,MyTireName);
%obj.setWheelSpring(2,DefaultCarSpring);


%obj.setWheelTire(1,DefaultCarTire);
%obj.setWheelSpring(1,DefaultCarSpring);


%obj.setWheelTire(0,DefaultCarTire);
%obj.setWheelSpring(0,DefaultCarSpring);

You can specify different tires and springs for each wheel on the vehicle, and the onAdd function is where it all happens. Also here you can specify whether the wheel is a drive wheel:

%obj.setWheelPowered(X,BOOL); //where X = the wheel index, BOOL = true for powered. false for unpowered

And you can specify if the wheel steers the vehicle:

%obj.setWheelSteering(X,BOOL);//where X = the wheel index, BOOL = true or false for steering
#3
12/13/2003 (8:20 pm)
Well naming it something else doesn't work. It needs to be a WheeledVehicleTire or it wont work as a car.

What was happening is that my
WheeledVehicleData::onAdd(%this,%obj)

was being "over ridden" by the last one created (makes sense) Within that function it setWheelTire. As a result which everyone was defined last won on my tire battle.

A temp fix (I am sure I will find something better than this) is to alter the "WheeledVehicleData::onAdd(%this,%obj)" to something like:

if(%obj.dataBlock $= "DefaultCar2") // its a Car2 so add the tires for that.
      {
            %obj.setWheelTire(%i,DefaultCar2Tire);


      }
      else
      {
          %obj.setWheelTire(%i,DefaultCarTire);
      }

Thanks for the suggestion though. It did head me down the path which resulted in the answer above.
#4
12/13/2003 (8:29 pm)
Martin,

Might be my implementation, but your suggestion doesn't work because it seems I can only have 1 "WheeledVehicleData::onAdd(%this,%obj)" which is called by both vehicles on creation.

What I have in my last post seems to be working.

Are you trying to poing me towards a better solution? It seems to me that you are pointing out how to get different tires on 1 vehicle. Thats not the problem. It was getting 2 vehicles to have different tires.
#5
12/13/2003 (9:13 pm)
This is what Blake means by name it something else. What I have in Bold is what needs name changes. Here is an example

Datablock WheeledVehicleTire(TankCarTire)
//Code


datablock WheeledVehicleSpring(TankCarSpring)
//Code


datablock WheeledVehicleData((TankCar)
//Code


function TankCar::onAdd(%this,%obj)
{
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,TankCarTire);
%obj.setWheelSpring(%i,TankCarSpring);

//More Code
#6
12/14/2003 (12:50 pm)
Ah yes, I misunderstood, I thought he was wanting 2 different types of tires on the same vehicle. As Michael demonstrates, you can have a seperate onAdd function for each vehicle you make, just use it's dataBlock name instead of WheeledVehicleData.
#7
12/14/2003 (1:06 pm)
Michael -

You are correct. I now know what he ment by rename it. When I tried "renaming it" I went way nuts (due to my ignorance) and renamed every occurance of "WheeledVehicleData" to the other name.

I have things running more like I would want them too.

Thank you very much!