Game Development Community

Particle effect

by Temasek Polytechnic · in Torque Game Engine · 10/17/2006 (7:21 pm) · 11 replies

Ok. This is not easy to explain, but i'll try.

Is it posible to add particles effect on AIPlayers such that it only plays when the AIPlayer is added into the world?

You know in some games, when you add an object, there is like a golden dust that appears around the newly added object, and then it disappears.

Something like this:
h1.ripway.com/rajjie/Game/particle.gif
I know it has something to do with the built in particle system, but i'm not sure how to go about doing it.

#1
10/17/2006 (8:35 pm)
Ummm... spawn a particle system at the same position when you create the aiplayer? And schedule it to be deleted a short time later? If you want it to actually be mounted to the aiplayer, that requires some modification, but for a spawn in effect, that's not really necessary.
#2
10/17/2006 (8:45 pm)
How do you spawn a particle system?

Sorry, i'm still new to this particle thing..
#3
10/17/2006 (9:07 pm)
%newParticleEmitter = new ParticleEmitterNode() { 
      emitter = myParticleEmitter;
      datablock = myParticleEmitterNode;
   };
The "emitter" field is where you put the datablock of the actual particle system you want to use, the "datablock" field should be a particleEmitterNode datablock. You generally only need one particleEmitterNode datablock for all particle systems, it's just an object that serves as a generic particle system renderer that does nothing else (the particle system is used other ways by objects internally in the engine. The only settings it has are playback speed of the particle system, so I just create a "defaultParticleEmitterNode" datablock and use that.

See the chimneyFire.cs in the starter.fps for examples of all the different parts you need for a particle system. There are three parts in total. The ParticleEmitterNode, which is only relevant when you spawn particle systems on their own, and generally only needs to be one of these. The ParticleEmitter, which contains definitions for how to emit the particles. This is what is used for reference in a ParticleEmitterNode, as well as particle definitions in things like a projectiles particle fields. The third is the Particle object itself, which is where the texture, lifetime, size, etc. settings for each individual particle are set.
#4
10/19/2006 (7:40 pm)
Onadd::
#5
10/19/2006 (8:02 pm)
Quote:Onadd::

What is that??
#6
10/19/2006 (8:40 pm)
He meant the "::onadd()" callback on datablocks. So, in your playerdata::onadd() callback, create an instance of the particle system. The particle system should probably set a timer on itself to delete itself a few seconds later. Also note that particle systems can be set to only generate particles for a given time, so that the effect can play out before it gets deleted.
#7
10/19/2006 (11:22 pm)
I've done it, but my aiplayer seems to be on fire...

This is what i got:
h1.ripway.com/rajjie/Game/particles2.gif

I'm trying to get like the effect below:
h1.ripway.com/rajjie/Game/particle.gif

This is my code:
// particle.cs
//
// Adds a "shimmerring" effect when new animals are added

datablock ParticleData(ShimmerParticle)
{
	textureName        = "~/data/shapes/particles/shimmer";
	dragCoefficient    = 0.0;
	gravityCoefficient = -0.3; // Gravity pulls down, but a negative value makes the particles rise instead of sink
	inheritedVelFactor = 0.50;
	useInvAlpha        = false;
	spinRandomMin      = -30.0;
	spinRandomMax      = 80.0;

	lifetimeMS         = 500;
	lifetimeVarianceMS = 250;

	times[0] = 0.0;
	times[1] = 0.5;
	times[2] = 1.0;
	times[3] = 1.5;

	colors[0] = "1.0 1.0 0.0 0.8";
	colors[1] = "1.0 1.0 0.0 0.8";
	colors[2] = "0.3 1.0 1.0 0.8";
	colors[3] = "1.0 1.0 0.0 0.2";

	sizes[0] = 2.0;
	sizes[1] = 2.0;
	sizes[2] = 4.0;
	sizes[2] = 4.0;
};

datablock ParticleEmitterData(ShimmerParticleEmitter)
{
	particles = "ShimmerParticle";

	ejectionPeriodMS = 15;
	periodVarianceMS = 5;
	
	//lifetimeMS = 5000;
	orientParticles = true;

	ejectionVelocity = 0.25;
	velocityVariance = 0.10;

	thetaMin = 90.0;
	thetaMax = 360.0;
};

datablock ParticleEmitterNodeData(ShimmerEmitterNode)
{
	timeMultiple = 1;
};

Does anyone know how i can modify my code to make it work?
#8
10/21/2006 (2:50 pm)
This is akin to saying "I built a car model, but it looks bad; how can I make it look good" :-)

It looks, though, like you want to make the size of each particle a lot smaller. That's the "sizes[]" array. I would set the three first values to something between 0.1 and 0.3, and the last value to something like 1.0. I would reduce the alpha of colors[2] to 0.5, and alpha of colors[3] to 0.0.

That ought to give you a start. You probably should check out the particle editor for an easier way to try out various changes to particle systems.
#9
10/21/2006 (8:13 pm)
Add a reload function at the top (I just posted this tip about an hour ago actually)

Then you can place the particles in the scene and keep reloading after every tweak until you get exactly what you wanted. This is where the reload function is the most useful.
#10
10/23/2006 (6:30 am)
You might already know this but if u hit f5 in game you can edit the particles... i think its f5.
#11
10/23/2006 (6:35 am)
I'm trying to do the same thing with the campfire.... I'd like to use the campfire::onAdd to create my fire emitter right above it but don't seem to be going in the right direction for it. Can someone give me an example of spawning the emitter with the campfire::onAdd ? Any help is greatly appreciated.