Game Development Community

Something about Cars

by CodingChris · in Torque Game Engine · 10/16/2006 (7:41 am) · 10 replies

Hello,

I'm new to Torque and I have a few questions about cars.

1. Car Collision
How to modify the car.cs that when the car collides, pieces of the car flew around. (like in Flat OUT).
I found a text that says how to do this:

With the existing code base you can make a debris file. . .basically a file containing all the parts of the vehicle, wheels, fenders, steering wheel whatever. Make sure each mesh is at the origin of the world (they will be overlapping). Then when the vehciles' damage is at zero it will trigger the debris file and fling all those lovely part all over the place.

But I don't know how to do this...

2. How to make the bot as player???
I use the Vehicle AI for Bots. How to make this bots as players. That also the bot could win???

Hope this is understandable...

Thanks

#1
10/16/2006 (10:35 am)
1. Hi, now i understand that you probably havent purchased 3d game programming all in one. nor advanced 3d game programming all in one. in the advanced book it teaches to make a glass shape and make the parts of the glass fall off detecting which part of the glass it has hit they use particles in this too. You should actually edit that file oh ofcourse heres the code of the glass though i dont think this is legal. though anyway:

[code] // Window Shattering


datablock AudioProfile(GlassShatterSound)
{
filename = "~/data/sound/windows/glassshatter.ogg";
description = AudioDefault3d;
preload = true;
};

datablock ParticleData(GlassShatterSmoke)
{
textureName = "~/data/shapes/windows/glass.jpg";
dragCoeffiecient = 100.0;
gravityCoefficient = 1.5;
inheritedVelFactor = 0.05;
constantAcceleration = -0.30;
lifetimeMS = 800;
lifetimeVarianceMS = 100;
useInvAlpha = false;
spinRandomMin = -80.0;
spinRandomMax = 80.0;

colors[0] = "0.8 0.8 0.8 0.2";
colors[1] = "0.7 0.7 0.7 0.2";
colors[2] = "0.9 0.9 0.9 0.2";

sizes[0] = 0.5;
sizes[1] = 0.2;
sizes[2] = 0.1;

times[0] = 0.1;
times[1] = 0.5;
times[2] = 0.3;
};


datablock ParticleEmitterData(GlassShatterSmokeEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 0;
ejectionVelocity = 8;
velocityVariance = 2;
thetaMin = 0.0;
thetaMax = 180.0;
lifetimeMS = 250;
particles = "GlassShatterSmoke";
};

datablock ParticleData(GlassShatterFire)
{
textureName = "~/data/shapes/windwos/glass.jpg";
dragCoeffiecient = 100.0;
gravityCoefficient = 2.0;
inheritedVelFactor = 0.1;
constantAcceleration = 0.0;
lifetimeMS = 300;
lifetimeVarianceMS = 200;
useInvAlpha = false;
spinRandomMin = -80.0;
spinRandomMax = 80.0;

colors[0] = "0.9 0.9 0.9 0.2";
colors[1] = "0.8 0.8 0.0 0.2";
colors[2] = "0.7 0.3 0.0 0.2";

sizes[0] = 0.7;
sizes[1] = 0.3;
sizes[2] = 0.2;

times[0] = 0.0;
times[1] = 0.3;
times[2] = 0.6;
};

datablock ParticleEmitterData(GlassShatterFireEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 0;
ejectionVelocity = 0.2;
velocityVariance = 0.05;
thetaMin = 0.0;
thetaMax = 180.0;
lifetimeMS = 250;
particles = "GlassShatterFire";
};

datablock ParticleData(GlassShatterSparks)
{
textureName = "~/data/shapes/windows/glass.jpg";
dragCoefficient = 1;
gravityCoefficient = 0.0;
inheritedVelFactor = 0.2;
constantAcceleration = 0.0;
lifetimeMS = 500;
lifetimeVarianceMS = 350;

colors[0] = "0.60 0.40 0.30 0.2";
colors[1] = "0.60 0.40 0.30 0.2";
colors[2] = "1.0 0.40 0.30 0.2";

sizes[0] = 0.25;
sizes[1] = 0.15;
sizes[2] = 0.15;

times[0] = 0.3;
times[1] = 0.4;
times[2] = 0.5;
};
#2
10/16/2006 (10:36 am)
Continuing:

datablock ParticleEmitterData(GlassShatterSparkEmitter)
{
ejectionPeriodMS = 3;
periodVarianceMS = 0;
ejectionVelocity = 2;
velocityVariance = 1;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 180;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
orientParticles = true;
lifetimeMS = 100;
particles = "GlassShatterSparks";
};

datablock ExplosionData(GlassSubExplosion1)
{
offset = 0;
emitter[0] = GlassShatterSmokeEmitter;
emitter[1] = GlassShatterSparkEmitter;
};

datablock ExplosionData(GlassSubExplosion2)
{
offset = 1.0;
emitter[0] = GlassShatterSmokeEmitter;
emitter[1] = GlassShatterSparkEmitter;
};


//-----------------------------------------------------------------------------
// Explosion Debris

// Debris "spark" explosion
datablock ParticleData(GlassDebrisSpark)
{
textureName = "~/data/shapes/windows/glass.jpg";
dragCoefficient = 0;
gravityCoefficient = 0.0;
windCoefficient = 0;
inheritedVelFactor = 0.5;
constantAcceleration = 0.0;
lifetimeMS = 500;
lifetimeVarianceMS = 50;
spinRandomMin = -90.0;
spinRandomMax = 90.0;
useInvAlpha = false;

colors[0] = "0.8 0.8 0.8 0.2";
colors[1] = "0.8 0.8 0.8 0.2";
colors[2] = "0.8 0.8 0.8 0.2";

sizes[0] = 0.2;
sizes[1] = 0.3;
sizes[2] = 0.1;

times[0] = 0.1;
times[1] = 0.3;
times[2] = 0.5;
};

datablock ParticleEmitterData(GlassDebrisSparkEmitter)
{
ejectionPeriodMS = 20;
periodVarianceMS = 0;
ejectionVelocity = 0.5;
velocityVariance = 0.25;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 90;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvances = false;
orientParticles = false;
lifetimeMS = 300;
particles = "GlassDebrisSpark";
};

datablock ExplosionData(GlassDebrisExplosion)
{
emitter[0] = GlassDebrisSparkEmitter;

// Turned off..
shakeCamera = false;
impulseRadius = 0;
lightStartRadius = 0;
lightEndRadius = 0;
};

// Debris smoke trail
datablock ParticleData(GlassDebrisTrail)
{
textureName = "~/data/shapes/windows/glass.jpg";
dragCoefficient = 1;
gravityCoefficient = 2;
inheritedVelFactor = 0;
windCoefficient = 0;
constantAcceleration = 0;
lifetimeMS = 200;
lifetimeVarianceMS = 100;
spinSpeed = 0;
spinRandomMin = -90.0;
spinRandomMax = 90.0;
useInvAlpha = false;

colors[0] = "0.8 0.8 0.8 0.2";
colors[1] = "0.8 0.8 0.8 0.2";
colors[2] = "0.8 0.8 0.8 0.2";

sizes[0] = 0.2;
sizes[1] = 0.3;
sizes[2] = 0.4;

times[0] = 0.1;
times[1] = 0.2;
times[2] = 0.3;
};

datablock ParticleEmitterData(GlassDebrisTrailEmitter)
{
ejectionPeriodMS = 30;
periodVarianceMS = 0;
ejectionVelocity = 0.0;
velocityVariance = 0.0;
ejectionOffset = 0.0;
thetaMin = 170;
thetaMax = 180;
phiReferenceVel = 0;
phiVariance = 360;
//overrideAdvances = false;
//orientParticles = true;
lifetimeMS = 1000;
particles = "GlassDebrisTrail";
};
// Debris object
datablock DebrisData(GlassShatterDebris)
{
shapeFile = "~/data/shapes/windows/glassdebris.dts";
// emitters = "GlassDebrisTrailEmitter";
// explosion = GlassDebrisExplosion;

elasticity = 0.2;
friction = 0.5;
numBounces = 2;
bounceVariance = 1;
explodeOnMaxBounce = false;
staticOnMaxBounce = false;
snapOnMaxBounce = false;
minSpinSpeed = 0;
maxSpinSpeed = 700;
render2D = false;
lifetime = 1;
lifetimeVariance = 0.5;
velocity = 20;
velocityVariance = 10;
fade = true;
useRadiusMass = true;
baseRadius = 0.25;
gravModifier = 2.0;
terminalVelocity = 100;
ignoreWater = true;
};

datablock ExplosionData(GlassShatter)
{
soundProfile = GlassShatterSound;
lifeTimeMS = 1000;

// Camera Shaking
shakeCamera = true;
camShakeFreq = "10.0 11.0 10.0";
camShakeAmp = "1.0 1.0 1.0";
camShakeDuration = 0.5;
camShakeRadius = 10.0;

// Exploding debris
debris = GlassShatterDebris;
debrisThetaMin = 90;
debrisThetaMax = 270;
debrisPhiMin = 0;
debrisPhiMax = 360;
debrisNum = 60;
debrisNumVariance = 20;
debrisVelocity = 1;
debrisVelocityVariance =0.5;

// Impulse
impulseRadius = 30;
impulseForce = 25;

// Dynamic light
lightStartRadius = 9;
lightEndRadius = 4;
lightStartColor = "0.5 0.5 0";
lightEndColor = "0 0 0";
};

//////////////////////////////////////////////////////////////////




datablock StaticShapeData(WindowA)
{
category = "windows";
shapeFile = "~/data/shapes/windows/window1.dts";
damageRadius = 10;
radiusDamage = 50;
damageType = WindowAdebris;
maxDamage = 5;
};

datablock StaticShapeData(Shards0)
{
category = "windows";
shapeFile = "~/data/shapes/windows/shards0.dts";
};

datablock StaticShapeData(Shards1)
{
category = "windows";
shapeFile = "~/data/shapes/windows/shards1.dts";
};

datablock StaticShapeData(Shards2)
{
category = "windows";
shapeFile = "~/data/shapes/windows/shards2.dts";
};

datablock StaticShapeData(Shards3)
{
category = "windows";
shapeFile = "~/data/shapes/windows/shards3.dts";
};

datablock StaticShapeData(Shards4)
{
category = "windows";
shapeFile = "~/data/shapes/windows/shards4.dts";
};

function WindowA::Damage(%theDatablock,%aWindow,%sourceObject,%pos,%damage,%damagetype)
{
%aWindow.applyDamage(%damage);
if(%aWindow.getDamageLevel() >= %theDatablock.maxDamage)
%theDatablock.Explode( %aWindow, %pos, %sourceObject);
}


function WindowA::Explode(%theDatablock, %aWindow, %position, %sourceObject)
{
if(%aWindow.exploded)
return;
%aWindow.exploded = true;
%boom = new Explosion()
{
datablock = GlassShatter;
position = %position;
};
MissionCleanup.add(%boom);
radiusDamage(%aWindow,%position,%theDatablock.damageRadius,
%theDatablock.radiusDamage,%sourceObject.damageType,%theDatablock.damageImpulse);

%r = GetRandom(4);
%db = "Shards" @ %r;

%wreckage = new StaticShape()
{
datablock = %db;
};
%wreckage.setTransform(%aWindow.getTransform());
%wreckage.setScale(%aWindow.getScale());
%aWindow.schedule(200, "delete");
MissionCleanup.add(%wreckage);
}
//------------------------------------------------------------------------------------------------
#3
10/16/2006 (10:38 am)
Hope this helps.




Saska.
#4
10/22/2006 (6:29 am)
Yes it does. I will buy the book.
#5
10/22/2006 (6:34 am)
That took quite a while to answer :)

i like to help :)
#6
10/22/2006 (6:37 am)
Yes, and try to use this code now. I was very busy last week, sorry.
#7
10/24/2006 (2:16 am)
Ok well good luck!

Tell me if it helped.
#8
10/24/2006 (6:48 am)
It didn't work because I didn't have all the textures models and all the things. I tried to make them self, but no luck. Now I bought the Bravetree Car Pack. But there is one problem... Where is the or what code says ever when the bot collides with the car, drove a cycle. I want to change this, so that ever when the bot drives, he followed his Path. Did you know where this is?
#9
10/24/2006 (8:31 am)
If you know how to make a path , make it all you have to do is mount the bot to the car to follow the path its that easy!
#10
01/03/2007 (2:18 am)
I now know why it does not work: My DefaultCar mass was a little bit crazy.