Game Development Community

Vehicle FX questions

by Ronald J Nelson · in Torque Game Engine · 11/07/2007 (5:43 pm) · 8 replies

I have been puzzling over how to approach a couple things and would like some suggestions as I know a few of you have already done these things

First, sparks created by vehicle collisions. I first try to set this up in code and it got to be a very big mess that only ended up killing my game. How did you do it? Or do you have a suggestion?

Second, smoke from tires. I have been playing with the particle emitters and particles and frankly mine still come out in puffs. I would like to be able to have a nice stream of smoke that would come from the tires when they slip. Any ideas?

Skid marks. I have been trying for a while now to get a dynamic decal system in place. Ironically I have gotten older code such as wrapping decals and fx decals to work with the newer engine, But they aren't what I need for this. What I am looking at trying to make is a nice continous black streak of rubber. I saw Brett Fatori had gotten something like this to work, but its been a couple of months since he has been around and he doesn't answer his email. Have any of you gotten these to work? If so would you share the way or throw me a hint or two?

Finally, Wheel slipping causing constant emitters. Frankly I have tried to fix this the way it should work by adjusting the static and kinetic friction values, but the wheels still seem to be registering as slipping at all times. Any ideas how to stop this?

Thanks in advance for any help or suggestions you can throw my way. I am more than willing to do the work, I am just hitting a brick wall in a few places.

#1
11/11/2007 (1:25 am)
Anyone? Frankly one that I have seen others do is the collision sparks. Can someone throw me a bone on how I should approach this?
#2
11/16/2007 (5:21 am)
Ron, I can tell you how I have done some of these things..

For sparks, I added a new set of emitters to my vehicle class, which I called 'flexible emitters'. These are like regular vehicle smoke emitters except they also have their Point3F locations defined in the vehicle's world-space, along with a 'type of emitter' variable which defines whether they are sparks, flame, or smoke. I basically iterate thru them and have them do their emitter thing in Vehicle::updateDamageSmoke. The server tells the client when to add a flexible emitter to a vehicle, along with the position of the emitter and the other relevant data (frequency, lifetime, etc.). Sparks are emitted from the 3D position at which a collision occurs, and the lifetime/frequency is based on how heavy the collision was.

For skid mark decals I added extra fields to the DecalInstance struct in sim/decalManager.h. These fields are (i) a flag indicating whether this is a skidmark decal, (ii) points to the previous and next skidmark decals (if any) that this one is linked to. When rendering these decals, the first 2 vertices of the polygon come from the previous decal rather than the current one. This gives you a continuous strip of decals.

Wheels usually have some amount of slip, yes. But it's stored as an F32, between 0 and 1 if I recall. So basically, you only want to emit smoke/skidmarks etc. if a wheel has a slip value of >0.95 or whatever.
#3
11/16/2007 (6:20 am)
Quote:like regular vehicle smoke emitters except they also have their Point3F locations defined in the vehicle's world-space, along with a 'type of emitter' variable which defines whether they are sparks, flame, or smoke.
Hi Sam... sorry to butt in... but could you give us some more info on this please?
I'm making a biplane sim, and could really use a feature like this.

Quote:Point3F locations defined in the vehicle's world-space
this is the bit that confuses me. it might as well be in ancient greek. lol..
could you post an example flexible emitter? or is that being too cheeky?
i'm new... but i would like to learn.

thankyou.
#4
11/16/2007 (6:56 am)
Ken,

No, it's not cheeky. The reason I don't post code here normally is because of the effort involved rather than some kind of secrecy. The main problem is that I'm working from a codebase that's a looooong way from the standard TGE one, since I've been modifying it for the past 2.5 years. So anything I post is unlikely to work out-of-the-box because it relies on other changes I have made along the way, some of which I have probably forgotten.

If you take a look in Vehicle::resolveCollision() you'll see that the collision list that's processed consists of items that have a 'point' member. This is the 3D world point at which the collision happened. The problem is if you want flames or smoke to emit from the vehicle at that position, it would be no good if the vehicle moved. But it's easy to turn it into a local co-ordinate using:

Point3F pt;
mWorldToObj.mulP(pos, &pt);

(I have assumed that pos contains the collision point in the world coordinate system).

Now if you take a look in Vehicle::updateDamageSmoke() you can see how the particle emitter built into the vehicle class emits particles. Basically, your spark/flame/smoke emitter does the same, except rather than using a hard-coded position (mDataBlock->damageEmitterOffset[0]), it uses the value calculated above.

Regarding an 'example of a flexible emitter', I can post the following, although it's probably of marginal use to a standard TGE codebase:

for (S32 i=0; i<NUMFLEXIBLEEMITTERS; i++) {
		if (mFlexibleEmitters[i].lifetimeEnd > gDarkwindTime && mFlexibleEmitters[i].lifetimeStart<=gDarkwindTime) {
			// this flexibleemitter is currently in effect
			S32 type = (S32)mFlexibleEmitters[i].type;
			Point3F emitterPoint = mFlexibleEmitters[i].offset;
			trans.mulP( emitterPoint );

			if( mDamageEmitterList[type] )
				mDamageEmitterList[type]->emitParticles(emitterPoint, emitterPoint, Point3F( 0.0, 0.0, 1.0 ), getVelocity(), (U32)(mFlexibleEmitters[i].density * dt * 1000));
		}
	}

Basically I use an array of 'flexible emitters', each of which has a 'type'. There are 4 types of actual particles emitted (sparks, flame, smoke, bluesmoke) and I use four Damage Emitters in my Vehicle class: mDamageEmitterList[type] selects the correct one to emit particles for each flexible emitter. This means I can have any number of emission locations but only had to add 4 actual emitter objects to the vehicle class.
#5
11/16/2007 (7:00 am)
And over in vehicle.h:

#define NUMFLEXIBLEEMITTERS 16

enum FlexibleEmitterType {
	Smoke			= 0,
	Flames			= 1,
	Sparks			= 2,
	BlueSmoke		= 3
};

struct FlexibleEmitter {
	FlexibleEmitterType	type;  
	S32					lifetimeEnd;	// darkwindtime at which it's finished
	S32					lifetimeStart;	// darkwindtime at which it starts
	Point3F				offset;			// offset from centre of vehicle
	F32					density;		// scale factor for amount of particles to emit
};

and a bit further down, inside the Vehicle class itself:

FlexibleEmitter	mFlexibleEmitters[NUMFLEXIBLEEMITTERS];
#6
11/16/2007 (7:36 pm)
Wow hey thanks Sam but I managed to get this already (with some help, thanks Brian) by setting up an explosion(that is pretty much just the emitter) at the point of impact. This is useful because I use the material mapping code to read the material and select the appropriate explosion/emmiter.

However, your code for the skid marks is exactly what I needed. Even just the way you did it was all I needed and I thank you for that. I kind of feel stupid that I didn't think of that on my own. Kind of had a case of having tunnel vision I suppose.

Thanks again.
#7
11/17/2007 (12:02 am)
Ok thanks to Sam's suggestions I did make a linked decal system and I did get my slipping code fixed up. I also have an impact spark system in place.

The only thing I still stink at is my dust emitters. Basically I need it to be a more steady stream of smoke.

Oh yeah, I don't suppose anyone knows how to do burn outs do they?
#8
11/19/2007 (7:14 am)
Thanks for explaining it, Sam.
very much appreciated.
cheers..