Game Development Community

How do I change vehicle model on the fly?

by EricCartman · in Technical Issues · 08/20/2002 (9:41 pm) · 16 replies

I have tried:

%client.player.dataBlock = "newCar"

where "newCar" is a dataBlock with a different vehicle model. I have tried at startup and it works. However, when I tried to get it change model in game, it doesnt change?

Do I need to tell the server to do a refresh or something?

thanks in advance.

#1
09/17/2002 (11:49 am)
Ever get anywhere on this? I'm having a simmilar problem.
#2
09/17/2002 (12:02 pm)
What exactly are you trying to do? Are you trying to change which vehicle your player is driving/flying/travelling in?
#3
09/17/2002 (12:37 pm)
I'm trying to create different damage models for vehicles. It sounds like it should be relatively easy, if the damage is below this threshold, change the shapeFile. But I'm not sure how to do the actual switching in script. I don't have the code infront of me at the moment but the last way I was trying it was to:
1) get the transform for the current vehicle
2) get the velocity of the current vehicle
3) delete the vehicle and unmount the player
4) create the new vehicle and remount the player
5) give the new vehicle the transform and velocity of the old one.

That's doesn't really work, and doesn't even really seem practical. Isn't there a way to just changes the actual DTS shapeFile?
#4
09/17/2002 (12:58 pm)
I don't know if this will work, but look at the debris datablocks in player.cs file, and see if you can paste those into the vehicle script file that you are using. Essentially, Torque replaces your player model with a different one when you die, so it's possible to assume that it might work with vehicles. Experimentation is the order of the day I'm afraid.

Edit:

Hmm I just tried the above and I can use say a tyre/tire for the debris data for the vehicle, but it doesn't remove the original vehicle. Also, don't forget that if the vehicle is destroyed while a player is inside, that player must be damaged/killed as well...
#5
09/17/2002 (1:04 pm)
Since more than likely nothing is animated on the car, why not just make the different crash levels sequences of animations? They wouldn't have to animate but if they hit something couldn't you just make the shape move on to the next sequence?

I haven't tried it myself so I couldn't tell you if it would work.
#6
09/17/2002 (1:07 pm)
You could create an animation that shows the car debris and set the animation running when the car is destroyed.
#7
09/17/2002 (1:31 pm)
hmmm... I didn't think about using an animation, I'll have to give it a try later. Although what would happen if I also had an animation for the door opening?

Ideally what I want to do is have different parts falloff. I thought about taking the hidden node approach where part is hidden when damaged and a new piece is spawned at that position, then apply a little impulse to the newly spawned piece. Then it would look like actual pieces were falling off. Unfortunately, I'm not the greatest programmer and the tutorial for the hidden nodes uses the player model and I'm not sure how to apply that to a vehicle, but I'm still looking into that method. Thanks for the suggestions.
#8
09/17/2002 (1:33 pm)
It seems that the debris is actually objects that are ejected from the vehicle or player when it is destroyed. So if you copy the debris code from the player's datablock and add it to the vehicle, when the vehicle is destroyed, you'll see little objects being ejected during the explosion.

But I still don't know how to change the model. I imagine you'll have to use animation for this unless someone else has any ideas.
#9
09/17/2002 (2:14 pm)
I've had the debris working on vehicles for a while, they are great for when it's finally destroyed, but they don't help much for doing different damage levels. The damage emitters are also nice and work fine, but just having 3 levels of smoke pouring out of the top of the vehicle isn't the most realistic thing. I'm going to give the animation a shot when I get out of work and I'll post back my results.

It just really seams like there should be a setShapeFile function or something similar, I can see it being useful for a variety of different things.
#10
09/17/2002 (2:16 pm)
Are these three levels of smoke automatically managed by the engine, or do you have to manage them yourself? I didn't realise these existed.
#11
09/17/2002 (2:31 pm)
They are handled by the engine. You need to set up some particle and emitter datablocks, as well as tell your vehicle datablock what to use:

datablock ParticleData(LightDamageParticle)
{
   textureName          = "~/data/shapes/car/dustParticle";
   dragCoefficient      = 2.0;
   gravityCoefficient   = -0.1;
   inheritedVelFactor   = 0.1;
   constantAcceleration = 0.0;
   lifetimeMS           = 1000;
   lifetimeVarianceMS   = 0;
   colors[0]     = "0.46 0.46 0.46 1.0";
   colors[1]     = "0.16 0.16 0.16 0.0";
   sizes[0]      = 1.50;
   sizes[1]      = 3.0;
};

datablock ParticleEmitterData(LightDamageEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 6;
   velocityVariance = 3.0;
   ejectionOffset   = 0.0;
   thetaMin         = 5;
   thetaMax         = 60;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   particles = "LightDamageParticle";
};

datablock ParticleData(HeavyDamageParticle)
{
   textureName          = "~/data/shapes/car/dustParticle";
   dragCoefficient      = 2.0;
   gravityCoefficient   = -0.1;
   inheritedVelFactor   = 0.1;
   constantAcceleration = 0.0;
   lifetimeMS           = 2000;
   lifetimeVarianceMS   = 0.5;
   colors[0]     = "0.25 0.25 0.16 1.0";
   colors[1]     = "0.16 0.16 0.16 0.0";
   sizes[0]      = 2.50;
   sizes[1]      = 5.0;
};

datablock ParticleEmitterData(HeavyDamageEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 10;
   velocityVariance = 3.0;
   ejectionOffset   = 0.4;
   thetaMin         = 5;
   thetaMax         = 60;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   particles = "HeavyDamageParticle";
};

datablock ParticleData(CarExplosionParticle)
{
   dragCoefficient      = 2;
   gravityCoefficient   = 0.5;
   inheritedVelFactor   = 0.9;
   constantAcceleration = 0.0;
   lifetimeMS           = 900;
   lifetimeVarianceMS   = 200;
   textureName          = "~/data/shapes/car/explosionParticle";
   colors[0]     = "0.86 0.36 0.26 1.0";
   colors[1]     = "0.70 0.36 0.26 0.5";
   colors[2]     = "0.56 0.36 0.26 0.0";
   sizes[0]      = 8.5;
    sizes[1]      = 11.5;
   sizes[2]      = 17.0;
};

datablock ParticleEmitterData(CarExplosionEmitter)
{
   ejectionPeriodMS = 12;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 60;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   particles = "CarExplosionParticle";
};

datablock ExplosionData(CarExplosion)
{
//explosionShape APPEARS TO NOT WORK
   explosionShape = "~/data/shapes/car/explosion_test.dts";
   playSpeed = 1.0;
   particleEmitter = CarExplosionEmitter;
   particleDensity = 60;
   particleRadius = 1;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = true;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;
};


datablock DebrisData(CarDebri)
{
   explodeOnMaxBounce = false;

   elasticity = 0.15;
   friction = 0.5;

   lifetime = 30.0;
   lifetimeVariance = 0.0;

   minSpinSpeed = 40;
   maxSpinSpeed = 600;

   numBounces = 6;
   bounceVariance = 2.3;

   staticOnMaxBounce = true;
   gravModifier = 1.0;

   useRadiusMass = true;
   baseRadius = 1;

   velocity = 20.0;
   velocityVariance = 12.0;
};
Inside the vehicle's datablock:

datablock WheeledVehicleData(Car)
{
.......

   damageEmitter[0] = LightDamageEmitter;
   damageEmitter[1] = HeavyDamageEmitter;
   damageEmitter[2] = DestroyedEmittrer;
   damageEmitterOffset[0] = "0.0 -3.0 0.0 ";
   damageLevelTolerance[0] = 0.3;
   damageLevelTolerance[1] = 0.7;
   numDmgEmitterAreas = 1;

  explosion = CarExplosion; //explosionShape APPEARS TO NOT WORK
  debrisShapeName = "~/data/shapes/car/debri_car.dts";
  debris = CarDebri;

............
};

To be honest I don't even remember how I figured that out... but it works (just applied it to a clean version of the head yesterday). Also I can't remember if I tried adding more then 3 damage levels, but I would guess it would work. There was something wrong with the explosion data if I remember correctly, I think it didn't work at all. I'm looking at old code I have here that's about 3 months out of date and I can't really test on this box so that's why I'm taking guesses on some of this stuff, but the damage emitters I'm positive work.

edit:
as I read through this again I remembered something. The actual explosion with particles works, it's the explosionShape that I'm not sure of.
#12
09/17/2002 (2:36 pm)
That's awesome. Thanks! Is this a resource somewhere? If not, maybe you should post it as one.

Thanks again
#13
09/17/2002 (2:49 pm)
I don't think it is a resource... I'll add it now.
#14
09/17/2002 (3:26 pm)
Thanks Kevin; I'm sure many people (including me!) will benefit from this resource.
#15
09/23/2002 (3:05 pm)
Well I've figured out how to do what I wanted, the function is setDataBlock() which I found on this thread here.

I submitted the damage emitters as a resource like 5 days ago (sept. 17) and it has yet to go up.
#16
09/23/2002 (4:21 pm)
I think it takes a few days for the GG guys to get round to approving resources.