How do I attach particles to switch events?
by Rich Wilson · in Torque Game Engine · 02/07/2003 (12:34 pm) · 3 replies
Ok, I've scoured the forums for something pertaining specifically to this question and have not come up with something that applies directly to what I'm trying to figure out. This may seem like a n00b question, but since we're all learning here, I'll post it anyway.
I'm just getting into scripting, and I'm trying to figure out how to create a particle system object and have it activate on triggering from a script. The specific example in this case is getting a water fountain to work. I've figured out basic particle data block scripting, and can get them into the game via the editor, I just don't know how to make a particle entity that can have functions that are script controlled. Any ideas?
I'm just getting into scripting, and I'm trying to figure out how to create a particle system object and have it activate on triggering from a script. The specific example in this case is getting a water fountain to work. I've figured out basic particle data block scripting, and can get them into the game via the editor, I just don't know how to make a particle entity that can have functions that are script controlled. Any ideas?
About the author
#2
This is a copy of the code I use to create storm clouds when I have a hail storm.
This section is the block of code which actually creates an instance of the emitter in your game. Note: the schedule(5000, ....), this function will schedule something to happen X number of milliseconds down the road. So 5 seconds after the cloud is created, I have it deleted.
This code defines what a "CloudParticle" is.
And this code defines how those cloud particles are spit out of the emitter which you create in the game.
-Jared
02/10/2003 (2:05 am)
I'm going to add onto Tim's post, since he said it wasn't tested yet, so I wanted to give you something that I know works.This is a copy of the code I use to create storm clouds when I have a hail storm.
This section is the block of code which actually creates an instance of the emitter in your game. Note: the schedule(5000, ....), this function will schedule something to happen X number of milliseconds down the road. So 5 seconds after the cloud is created, I have it deleted.
function CreateHailCloud(%pos)
{
%cloudEmitterName = new ParticleEmitterNode(Cloud) {
position = %pos;
rotation = "0 0 0 0";
scale = "1 1 1";
dataBlock = "CloudEmitterNode";
emitter = "CloudEmitter";
velocity = "1";
};
schedule(5000, 0, "EmitterDelete", %cloudEmitterName);
MissionCleanup.add(%cloudEmitterName);
return %cloudEmitterName;
}
function EmitterDelete(%name)
{
%name.delete();
}
datablock ParticleEmitterNodeData(CloudEmitterNode)
{
timeMultiple = 1;
};This code defines what a "CloudParticle" is.
datablock ParticleData(CloudParticle)
{
dragCoefficient = 0;
gravityCoefficient = 0.461538;
windCoefficient = 0;
inheritedVelFactor = 0;
constantAcceleration = 0;
lifetimeMS = 1152;
lifetimeVarianceMS = 128;
useInvAlpha = 1;
spinRandomMin = -30;
spinRandomMax = 30;
textureName = "fps/data/shapes/particles/grayCloud.png";
spinSpeed = 114.706;
times[0] = 0;
times[1] = 0.101961;
times[2] = 1;
colors[0] = "1.000000 1.000000 1.000000 0.070866";
colors[1] = "1.000000 1.000000 1.000000 0.291339";
colors[2] = "0.102362 0.086614 0.102362 0.000000";
sizes[0] = 2.05701;
sizes[1] = 3.50668;
sizes[2] = 5.16084;
};And this code defines how those cloud particles are spit out of the emitter which you create in the game.
datablock ParticleEmitterData(CloudEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 5;
ejectionVelocity = 1.57;
velocityVariance = 1.87;
ejectionOffset = 1.87;
thetaMin = 90;
thetaMax = 90;
phiReferenceVel = 360;
phiVariance = 360;
overrideAdvances = 0;
orientParticles= 0;
orientOnVelocity = 1;
particles = "CloudParticle";
};-Jared
#3
02/10/2003 (11:06 am)
Thanks a million guys. This worked like a charm. Now I can have all the soda fountains I could ever hope to create.
Torque Owner Tim Gift
// Datablock for the emitter node datablock ParticleEmitterNodeData(DefaultEmitterNode) { timMultiple = 1; } // Start the fountain going $Fountain = new ParticleEmitterNode() { datablock = DefaultEmitterNode; emitter = FountainEmitter; velocity = 1; pos = FountainMarker.getPosition(); } // Fountain off $Fountain.delete();This is just an illustration of what you would do (haven't tested this code). FountainMarker could be a marker place in the mission editor where you want the fountain to appear.