Multiple cars in game
by James W. · in Torque Game Engine · 12/10/2007 (12:02 pm) · 6 replies
I'm using the car.cs from the starter.racing ported over to starter.fps.
When I try to put multiple cars in it reuses the defaultCarTire for each car.
I'm trying to figure out how to change it so the correct tire for the model can be used.
When I try to put multiple cars in it reuses the defaultCarTire for each car.
datablock WheeledVehicleTire(DefaultCarTire)
{
shapeFile = "~/data/shapes/car/wheel.dts";
....
};
datablock WheeledVehicleSpring(DefaultCarSpring)
{
// Wheel suspension properties
.....
}:
datablock WheeledVehicleData(DefaultCar)
{
category = "Vehicles";
...
};
function WheeledVehicleData::onAdd(%this,%obj)
{
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,DefaultCarTire); //<---This is wear my issue is, defaults are picked
%obj.setWheelSpring(%i,DefaultCarSpring); // how can I get it to load the specific tire for the model car
%obj.setWheelPowered(%i,false); // (%i,%this
}
// 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);
}
datablock WheeledVehicleTire(fordCoupeCarTire)
{
shapeFile = "~/data/shapes/fordCoupe/wheel.dts";
........
};
datablock WheeledVehicleData(fordCoupe)
{
category = "Vehicles";
shapeFile = "~/data/shapes/fordCoupe/car.dts";
.....
};I'm trying to figure out how to change it so the correct tire for the model can be used.
About the author
#2
i get this error here:
setWheelTire: datablock does not exist (or is not a tire)
setWheelSpring: datablock does not exist (or is not a spring)
setWheelTire: datablock does not exist (or is not a tire)
setWheelSpring: datablock does not exist (or is not a spring)
setWheelTire: datablock does not exist (or is not a tire)
setWheelSpring: datablock does not exist (or is not a spring)
setWheelTire: datablock does not exist (or is not a tire)
setWheelSpring: datablock does not exist (or is not a spring)
12/10/2007 (5:07 pm)
When I open the editor only one car is showing, and I put the car in the game it has no wheels i get this error here:
setWheelTire: datablock does not exist (or is not a tire)
setWheelSpring: datablock does not exist (or is not a spring)
setWheelTire: datablock does not exist (or is not a tire)
setWheelSpring: datablock does not exist (or is not a spring)
setWheelTire: datablock does not exist (or is not a tire)
setWheelSpring: datablock does not exist (or is not a spring)
setWheelTire: datablock does not exist (or is not a tire)
setWheelSpring: datablock does not exist (or is not a spring)
//----------------------------------------------------------------------------
datablock WheeledVehicleTire(CarTire)
{
// 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";
staticFriction = 4.2;
kineticFriction = 3.15;
// Spring that generates lateral tire forces
lateralForce = 18000;
lateralDamping = 6000;
lateralRelaxation = 1;
// Spring that generates longitudinal tire forces
longitudinalForce = 18000;
longitudinalDamping = 4000;
longitudinalRelaxation = 1;
};
datablock WheeledVehicleSpring(CarSpring)
{
// Wheel suspension properties
length = 0.85; // Suspension travel
force = 3500; // Spring force
damping = 3600; // Spring damping
antiSwayForce = 3; // Lateral anti-sway force
};
datablock WheeledVehicleData(Car)
{
category = "Vehicles";
shapeFile = "~/data/shapes/car/car.dts";
emap = true;
mountPose[0] = sitting;
maxDamage = 1.0;
destroyedLevel = 0.5;
maxSteeringAngle = 0.385; // Maximum steering angle, should match animation
tireEmitter = TireEmitter; // All the tires use the same dust emitter
// 3rd person camera settings
cameraRoll = true; // Roll the camera with the vehicle
cameraMaxDist = 4.8; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.26; // Velocity lag of camera
cameraDecay = 1.25; // Decay per sec. rate of velocity lag
// Rigid Body
mass = 380;
massCenter = "0 -0.2 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.6; // Drag coefficient
bodyFriction = 0.6;
bodyRestitution = 0.4;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 8; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
// Engine
engineTorque = 3300; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 8000; // When brakes are applied
maxWheelSpeed = 50; // Engine scale by current speed / max speed
// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;
// Sounds
// jetSound = ScoutThrustSound;
// engineSound = BuggyEngineSound;
// squealSound = ScoutSquealSound;
// softImpactSound = SoftImpactSound;
// hardImpactSound = HardImpactSound;
// wheelImpactSound = WheelImpactSound;
// explosion = VehicleExplosion;
};
//----------------------------------------------------------------------------
datablock WheeledVehicleTire(fordCoupe : CarTire)
{
// 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/fordCoupe/wheel.dts";
staticFriction = 4.2;
kineticFriction = 3.15;
// Spring that generates lateral tire forces
lateralForce = 18000;
lateralDamping = 6000;
lateralRelaxation = 1;
// Spring that generates longitudinal tire forces
longitudinalForce = 18000;
longitudinalDamping = 4000;
longitudinalRelaxation = 1;
};
datablock WheeledVehicleSpring(fordCoupe : CarSpring)
{
// Wheel suspension properties
length = 0.85; // Suspension travel
force = 2800; // Spring force
damping = 3600; // Spring damping
antiSwayForce = 3; // Lateral anti-sway force
};
datablock WheeledVehicleData(fordCoupe : car)
{
category = "Vehicles";
shapeFile = "~/data/shapes/fordCoupe/car.dts";
emap = true;
mountPose[0] = sitting;
maxDamage = 1.0;
destroyedLevel = 0.5;
maxSteeringAngle = 0.385; // Maximum steering angle, should match animation
tireEmitter = TireEmitter; // All the tires use the same dust emitter
// 3rd person camera settings
cameraRoll = true; // Roll the camera with the vehicle
cameraMaxDist = 4.8; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.26; // Velocity lag of camera
cameraDecay = 1.25; // Decay per sec. rate of velocity lag
// Rigid Body
mass = 380;
massCenter = "0 -0.2 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.6; // Drag coefficient
bodyFriction = 0.6;
bodyRestitution = 0.4;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 8; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
// Engine
engineTorque = 3300; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 8000; // When brakes are applied
maxWheelSpeed = 50; // Engine scale by current speed / max speed
// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;
// Sounds
// jetSound = ScoutThrustSound;
// engineSound = BuggyEngineSound;
// squealSound = ScoutSquealSound;
// softImpactSound = SoftImpactSound;
// hardImpactSound = HardImpactSound;
// wheelImpactSound = WheelImpactSound;
// explosion = VehicleExplosion;
};
//-----------------------------------------------------------------------------
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,%this.CarTire);
%obj.setWheelSpring(%i,%this.CarSpring);
%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
}
#3
I just want to make sure I understand this correctly
%obj.setWheelTire(%i,%this.carTire);
%obj.setWheelSpring(%i,%this.carSpring);
%this //meaning the model I am adding
.carTire // is the method of calling in the main model shape file
carTire = "fordCoupeCarTire";
carSpring = "fordCoupeCarSpring"; // this data is called/passed from the specific datablock being imported to the model
I just want to make sure I understand it, I start a C++ class tomorrow so hopefully I will get a better idea
12/11/2007 (9:33 am)
Well this works, datablock WheeledVehicleTire(CarTire)
{
// 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";
staticFriction = 4.2;
kineticFriction = 3.15;
// Spring that generates lateral tire forces
lateralForce = 18000;
lateralDamping = 6000;
lateralRelaxation = 1;
// Spring that generates longitudinal tire forces
longitudinalForce = 18000;
longitudinalDamping = 4000;
longitudinalRelaxation = 1;
};
datablock WheeledVehicleSpring(CarSpring)
{
// Wheel suspension properties
length = 0.85; // Suspension travel
force = 3500; // Spring force
damping = 3600; // Spring damping
antiSwayForce = 3; // Lateral anti-sway force
};
datablock WheeledVehicleData(Car)
{
category = "Vehicles";
shapeFile = "~/data/shapes/car/car.dts";
carTire = "CarTire";
carSpring = "CarSpring";
emap = true;
mountPose[0] = sitting;
maxDamage = 1.0;
destroyedLevel = 0.5;
maxSteeringAngle = 0.385; // Maximum steering angle, should match animation
tireEmitter = TireEmitter; // All the tires use the same dust emitter
// 3rd person camera settings
cameraRoll = true; // Roll the camera with the vehicle
cameraMaxDist = 4.8; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.26; // Velocity lag of camera
cameraDecay = 1.25; // Decay per sec. rate of velocity lag
// Rigid Body
mass = 380;
massCenter = "0 -0.2 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.6; // Drag coefficient
bodyFriction = 0.6;
bodyRestitution = 0.4;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 8; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
// Engine
engineTorque = 3300; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 8000; // When brakes are applied
maxWheelSpeed = 50; // Engine scale by current speed / max speed
// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;
// Sounds
// jetSound = ScoutThrustSound;
// engineSound = BuggyEngineSound;
// squealSound = ScoutSquealSound;
// softImpactSound = SoftImpactSound;
// hardImpactSound = HardImpactSound;
// wheelImpactSound = WheelImpactSound;
// explosion = VehicleExplosion;
};
//----------------------------------------------------------------------------
datablock WheeledVehicleTire(fordCoupeCarTire)
{
// 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/fordCoupe/wheel.dts";
staticFriction = 4.2;
kineticFriction = 3.15;
// Spring that generates lateral tire forces
lateralForce = 18000;
lateralDamping = 6000;
lateralRelaxation = 1;
// Spring that generates longitudinal tire forces
longitudinalForce = 18000;
longitudinalDamping = 4000;
longitudinalRelaxation = 1;
};
datablock WheeledVehicleSpring(fordCoupeCarSpring)
{
// Wheel suspension properties
length = 0.85; // Suspension travel
force = 2800; // Spring force
damping = 3600; // Spring damping
antiSwayForce = 3; // Lateral anti-sway force
};
datablock WheeledVehicleData(fordCoupe)
{
category = "Vehicles";
shapeFile = "~/data/shapes/fordCoupe/car.dts";
carTire = "fordCoupeCarTire";
carSpring = "fordCoupeCarSpring";
emap = true;
mountPose[0] = sitting;
maxDamage = 1.0;
destroyedLevel = 0.5;
maxSteeringAngle = 0.385; // Maximum steering angle, should match animation
tireEmitter = TireEmitter; // All the tires use the same dust emitter
// 3rd person camera settings
cameraRoll = true; // Roll the camera with the vehicle
cameraMaxDist = 4.8; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.26; // Velocity lag of camera
cameraDecay = 1.25; // Decay per sec. rate of velocity lag
// Rigid Body
mass = 380;
massCenter = "0 -0.2 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.6; // Drag coefficient
bodyFriction = 0.6;
bodyRestitution = 0.4;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 8; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
// Engine
engineTorque = 3300; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 8000; // When brakes are applied
maxWheelSpeed = 50; // Engine scale by current speed / max speed
// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;
// Sounds
// jetSound = ScoutThrustSound;
// engineSound = BuggyEngineSound;
// squealSound = ScoutSquealSound;
// softImpactSound = SoftImpactSound;
// hardImpactSound = HardImpactSound;
// wheelImpactSound = WheelImpactSound;
// explosion = VehicleExplosion;
};
//-----------------------------------------------------------------------------
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,%this.carTire);
%obj.setWheelSpring(%i,%this.carSpring);
%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
}I just want to make sure I understand this correctly
%obj.setWheelTire(%i,%this.carTire);
%obj.setWheelSpring(%i,%this.carSpring);
%this //meaning the model I am adding
.carTire // is the method of calling in the main model shape file
carTire = "fordCoupeCarTire";
carSpring = "fordCoupeCarSpring"; // this data is called/passed from the specific datablock being imported to the model
I just want to make sure I understand it, I start a C++ class tomorrow so hopefully I will get a better idea
#4
Now here's a little something else for you to know. The WheeledVehicleData::onAdd can be overridden by an onAdd specific to your datablock, which was originally the why I intended my answer to lead you, but the default stuff should work for you for now.
Basically you would only really need to override the onAdd when you start doing stuff to your vehicle that shouldn't happen to others, like for instance which wheels are powered, or the wheel steering, or even if you start adding turrets to vehicles.
12/11/2007 (10:38 am)
Correct, that will spawn your vehicle with its proper bits. Now here's a little something else for you to know. The WheeledVehicleData::onAdd can be overridden by an onAdd specific to your datablock, which was originally the why I intended my answer to lead you, but the default stuff should work for you for now.
Basically you would only really need to override the onAdd when you start doing stuff to your vehicle that shouldn't happen to others, like for instance which wheels are powered, or the wheel steering, or even if you start adding turrets to vehicles.
#5
I could have left the defaults in that function, and just added the datablock with the model and tire data and inherited the default spring/wheeledVehilce data from the default car datablocks.
12/11/2007 (11:54 am)
I think I understand what your saying.I could have left the defaults in that function, and just added the datablock with the model and tire data and inherited the default spring/wheeledVehilce data from the default car datablocks.
#6
08/16/2011 (8:40 pm)
I tried something like this but I'm having the problem of the new cars WheeledVehicleData::onAdd function overriding the default car's tires so the default car ends up loading the new tires.
Associate Scott Burns
GG Alumni