Wheeled Vehicle Question
by Matt Sanders · in Torque Game Engine · 01/03/2005 (1:09 pm) · 2 replies
I have so far been very pleased with the responces that I recieve from the garagegames community and again are asking for assistance. I am having problems trying to put more then one vehicle in the game. I am using a modifed version of the car.cs file that came with the engine for every vehicle. The problem lies with this piece of code...
function WheeledVehicleData::create(%block)
{
%obj = new WheeledVehicle() {
dataBlock = %block;
};
return(%obj);
}
//-----------------------------------------------------------------------------
function WheeledVehicleData::onAdd(%this,%obj)
{
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,ATVwheel);
%obj.setWheelSpring(%i,ATVSpring);
%obj.setWheelPowered(%i,false);
}
// 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);
}
function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects, including items
}
The problem that I am having is that every vehicle in my game has different tires and springs but Torque calls WheeledVehicleData::onAdd of only one of the .cs files and thus makes only one Tire type in this case ATVwheel. I was wondering what I have to modify to make it possible to use multiple vehicles with different tires.
A seperate question that I had was How to make the camera free look while you are in the vehicle. Any help is more then appreciated.....
function WheeledVehicleData::create(%block)
{
%obj = new WheeledVehicle() {
dataBlock = %block;
};
return(%obj);
}
//-----------------------------------------------------------------------------
function WheeledVehicleData::onAdd(%this,%obj)
{
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,ATVwheel);
%obj.setWheelSpring(%i,ATVSpring);
%obj.setWheelPowered(%i,false);
}
// 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);
}
function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects, including items
}
The problem that I am having is that every vehicle in my game has different tires and springs but Torque calls WheeledVehicleData::onAdd of only one of the .cs files and thus makes only one Tire type in this case ATVwheel. I was wondering what I have to modify to make it possible to use multiple vehicles with different tires.
A seperate question that I had was How to make the camera free look while you are in the vehicle. Any help is more then appreciated.....
#2
01/05/2005 (4:29 am)
Thank you Thank you Thank you.... That was the info I needed I am going to implament that right now. This helps out alot I am trying to get a better handle on scripting with torque script.....
Torque 3D Owner Martin "Founder" Hoover
DefaultCar::onAdd(%this, %obj)
ANother route would be to put the names of the tires and springs into the vehicle datablock, so you would have lines something like...
%obj.setWheelTire(%i, %obj.getDataBlock().tire);
Then you could continue using only the base onAdd method, but get values specific to the vehicles.
If you are using more then one type of tire or spring on the same vehicle you can make them array entries like so..
%obj.setWheelTire(%i, %obj.getDataBlock().tire[%i]); (would set the tire specified in tire[3] to to the hub slot 3)
But basically, anywhere you see a functon name that starts with the name of a dataBlock class (anything ending with data) you can overload for a particular instance by relacing it with the Datablock name.