Mounted Emitter control
by Jay Barbeau · in Technical Issues · 01/13/2007 (5:25 pm) · 0 replies
I am using a mounted particle emitter on my player. I want the particles to go all in one direction oriented the same to get an effect of a pulsed-beam firing. I also want the beam to automatically point at another player in the game. At first I just thought I'd use emitter and place them in position according to
%player.getPosition(). This doesn't work because emitters won't responed to setTransform() unless they are attached to something.
Instead, I am using code I found for a mounted emitted which is a little different. I have the emitter following the player, and outputting the particles correctly, but I can't seem to affect rotation of the emitter.
Here's the code.... sorry if I'm not supposed to put code in like this, Is there a way to attach it?
function mountedImage::shootParticles(%this, %obj, %slot)
{
// echo("preactivate");
%obj.setImageTrigger(1,false);
%projectile = %this.projectile;
%muzzleVector = %obj.getMuzzleVector(%slot); //"1 1 1 0";
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor)
);
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
datablock ParticleData(mountedParticle)
{
textureName = "~/data/shapes/particles/square";
};
datablock ParticleEmitterData(mountedEmitter)
{
className = "ParticleEmitterData";
ejectionPeriodMS = "80";
periodVarianceMS = "0";
ejectionVelocity = "20";
velocityVariance = "0";
ejectionOffset = "0";
thetaMin = "90";
thetaMax = "90";
phiReferenceVel = "1";
phiVariance = "0";
overrideAdvance = "0";
orientParticles = "1";
orientOnVelocity = "0";
particles = mountedParticle;
lifetimeMS = "5000";
lifetimeVarianceMS = "0";
useEmitterSizes = "0";
useEmitterColors = "0";
};
datablock ProjectileData(mountedProjectile)
{
gravityMod = 0.0;
hasLight = false;
};
function mountedImage::preStep(%this, %obj, %slot)
{
%obj.unmountImage(1);
}
datablock ShapeBaseImageData(mountedImage)
{
shapeFile = "~/data/shapes/dummy1/dummy1.dts";
..... code omitted...........
};
datablock ParticleEmitterNodeData(mountedEmitterNode)
{
timeMultiple = 0.1;
};
---------------------------------------------------------------------------------------------------
I experimented with the ParticleEmitter Editor, and found that for a beam emitter if I set:
thetaMin = 90.0;
thetaMax = 90.0;
then this parameter:
phiReferenceVel = (some radian value 0 to 2pi)
Will control the rotation of the emitter on the zx axis.
I'm using this code from a scheduled timer to change the rotation:
mountedEmitter.phiReferenceVel = $lx;
echo("phiReferenceVel=" @ mountedEmitter.phiReferenceVel);
%emit.setEmitterDataBlock("mountedEmitter");
I don't know what %emit should be though? The setup function for mounted emitter is this:
%player.mountImage(mountedImage,1);
and this works to start the emitter. But I don't get a handle for the ParticleEmitterNode like I do if I use
%PEnode = new ParticleEmitter()
So how can I change the EmitterDataBlock?
And will this work to rotate the emitter?
Do I need another command to tell the emitter to use the updated data??
Anyone done this?
thanx
%player.getPosition(). This doesn't work because emitters won't responed to setTransform() unless they are attached to something.
Instead, I am using code I found for a mounted emitted which is a little different. I have the emitter following the player, and outputting the particles correctly, but I can't seem to affect rotation of the emitter.
Here's the code.... sorry if I'm not supposed to put code in like this, Is there a way to attach it?
function mountedImage::shootParticles(%this, %obj, %slot)
{
// echo("preactivate");
%obj.setImageTrigger(1,false);
%projectile = %this.projectile;
%muzzleVector = %obj.getMuzzleVector(%slot); //"1 1 1 0";
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor)
);
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
datablock ParticleData(mountedParticle)
{
textureName = "~/data/shapes/particles/square";
};
datablock ParticleEmitterData(mountedEmitter)
{
className = "ParticleEmitterData";
ejectionPeriodMS = "80";
periodVarianceMS = "0";
ejectionVelocity = "20";
velocityVariance = "0";
ejectionOffset = "0";
thetaMin = "90";
thetaMax = "90";
phiReferenceVel = "1";
phiVariance = "0";
overrideAdvance = "0";
orientParticles = "1";
orientOnVelocity = "0";
particles = mountedParticle;
lifetimeMS = "5000";
lifetimeVarianceMS = "0";
useEmitterSizes = "0";
useEmitterColors = "0";
};
datablock ProjectileData(mountedProjectile)
{
gravityMod = 0.0;
hasLight = false;
};
function mountedImage::preStep(%this, %obj, %slot)
{
%obj.unmountImage(1);
}
datablock ShapeBaseImageData(mountedImage)
{
shapeFile = "~/data/shapes/dummy1/dummy1.dts";
..... code omitted...........
};
datablock ParticleEmitterNodeData(mountedEmitterNode)
{
timeMultiple = 0.1;
};
---------------------------------------------------------------------------------------------------
I experimented with the ParticleEmitter Editor, and found that for a beam emitter if I set:
thetaMin = 90.0;
thetaMax = 90.0;
then this parameter:
phiReferenceVel = (some radian value 0 to 2pi)
Will control the rotation of the emitter on the zx axis.
I'm using this code from a scheduled timer to change the rotation:
mountedEmitter.phiReferenceVel = $lx;
echo("phiReferenceVel=" @ mountedEmitter.phiReferenceVel);
%emit.setEmitterDataBlock("mountedEmitter");
I don't know what %emit should be though? The setup function for mounted emitter is this:
%player.mountImage(mountedImage,1);
and this works to start the emitter. But I don't get a handle for the ParticleEmitterNode like I do if I use
%PEnode = new ParticleEmitter()
So how can I change the EmitterDataBlock?
And will this work to rotate the emitter?
Do I need another command to tell the emitter to use the updated data??
Anyone done this?
thanx
About the author