Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Particle effects emmiting relative to the avatar?

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
11-05-2005 11:44
I've got a particle effect on a "gun" that I want to emit relative to the avatar (namely, I want the fire effect to always shoot forward from the barrel). the problem is, when I set the accelration, it makes the vector relative to the world. any suggestions on what I need to do to have the acceleration be relative to my avatar?


CODE
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//// eltee Statosky's Particle Creation Engine 1.2
//// 03/19/2004
//// *PUBLIC DOMAIN*
//// Free to use
//// Free to copy
//// Free to poke at
//// Free to hide in stuff you sell
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//// Changelog:
//// 1.2: (1) Seperated out variable value assignments to
//// dedicated function call (easier to copy/paste)
//// (2) Improved several comments
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
////// Particle System Variables
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////



///////////////////////////////////////////////////////
// Effect Flag Collection variable
///////////////////////////////////////////////////////
integer effectFlags;
integer running=TRUE;

///////////////////////////////////////////////////////
// Color Secelection Variables
///////////////////////////////////////////////////////
// Interpolate between startColor and endColor
integer colorInterpolation;
// Starting color for each particle
vector startColor;
// Ending color for each particle
vector endColor;
// Starting Transparency for each particle (1.0 is solid)
float startAlpha;
// Ending Transparency for each particle (0.0 is invisible)
float endAlpha;
// Enables Absolute color (true) ambient lighting (false)
integer glowEffect;

///////////////////////////////////////////////////////
// Size & Shape Selection Variables
///////////////////////////////////////////////////////
// Interpolate between startSize and endSize
integer sizeInterpolation;
// Starting size of each particle
vector startSize;
// Ending size of each particle
vector endSize;
// Turns particles to face their movement direction
integer followVelocity;
// Texture the particles will use ("" for default)
string texture;

///////////////////////////////////////////////////////
// Timing & Creation Variables Variables
///////////////////////////////////////////////////////
// Lifetime of one particle (seconds)
float particleLife;
// Lifetime of the system 0.0 for no time out (seconds)
float SystemLife;
// Number of seconds between particle emissions
float emissionRate;
// Number of particles to releast on each emission
integer partPerEmission;

///////////////////////////////////////////////////////
// Angular Variables
///////////////////////////////////////////////////////
// The radius used to spawn angular particle patterns
float radius;
// Inside angle for angular particle patterns
float innerAngle;
// Outside angle for angular particle patterns
float outerAngle;
// Rotational potential of the inner/outer angle
vector omega;

///////////////////////////////////////////////////////
// Movement & Speed Variables
///////////////////////////////////////////////////////
// The minimum speed a particle will be moving on creation
float minSpeed;
// The maximum speed a particle will be moving on creation
float maxSpeed;
// Global acceleration applied to all particles
vector acceleration;
// If true, particles will be blown by the current wind
integer windEffect;
// if true, particles 'bounce' off of the object's Z height
integer bounceEffect;
// If true, particles spawn at the container object center
integer followSource;
// If true, particles will move to expire at the target
//integer followTarget = TRUE;
// Desired target for the particles (any valid object/av key)
// target Needs to be set at runtime
key target;

///////////////////////////////////////////////////////
//As yet unimplemented particle system flags
///////////////////////////////////////////////////////
integer randomAcceleration = FALSE;
integer randomVelocity = FALSE;
integer particleTrails = FALSE;

///////////////////////////////////////////////////////
// Pattern Selection
///////////////////////////////////////////////////////
integer pattern;



///////////////////////////////////////////////////////
// Particle System Call Function
///////////////////////////////////////////////////////
setParticles()
{
// Here is where to set the current target

// Feel free to insert any other valid key
target="";
// The following block of if statements is used to construct the mask
if (colorInterpolation) effectFlags = effectFlags|PSYS_PART_INTERP_COLOR_MASK;
if (sizeInterpolation) effectFlags = effectFlags|PSYS_PART_INTERP_SCALE_MASK;
if (windEffect) effectFlags = effectFlags|PSYS_PART_WIND_MASK;
if (bounceEffect) effectFlags = effectFlags|PSYS_PART_BOUNCE_MASK;
if (followSource) effectFlags = effectFlags|PSYS_PART_FOLLOW_SRC_MASK;
if (followVelocity) effectFlags = effectFlags|PSYS_PART_FOLLOW_VELOCITY_MASK;
if (target!="") effectFlags = effectFlags|PSYS_PART_TARGET_POS_MASK;
if (glowEffect) effectFlags = effectFlags|PSYS_PART_EMISSIVE_MASK;
llParticleSystem([
PSYS_PART_FLAGS, effectFlags,
PSYS_SRC_PATTERN, pattern,
PSYS_PART_START_COLOR, startColor,
PSYS_PART_END_COLOR, endColor,
PSYS_PART_START_ALPHA, startAlpha,
PSYS_PART_END_ALPHA, endAlpha,
PSYS_PART_START_SCALE, startSize,
PSYS_PART_END_SCALE, endSize,
PSYS_PART_MAX_AGE, particleLife,
PSYS_SRC_ACCEL, acceleration,
PSYS_SRC_TEXTURE, texture,
PSYS_SRC_BURST_RATE, emissionRate,
PSYS_SRC_INNERANGLE, innerAngle,
PSYS_SRC_OUTERANGLE, outerAngle,
PSYS_SRC_BURST_PART_COUNT, partPerEmission,
PSYS_SRC_BURST_RADIUS, radius,
PSYS_SRC_BURST_SPEED_MIN, minSpeed,
PSYS_SRC_BURST_SPEED_MAX, maxSpeed,
PSYS_SRC_MAX_AGE, SystemLife,
PSYS_SRC_TARGET_KEY, target,
PSYS_SRC_OMEGA, omega ]);
}


///////////////////////////////////////////////////////
// Particle Effect Function
// - Edit the values here to change the effect
///////////////////////////////////////////////////////
ParticleFallsEffect()
{
//Color
colorInterpolation = TRUE;
startColor = <1, .5, 0>;
endColor = <0, 0, 0>;
startAlpha = 1.0;
endAlpha = 0;
glowEffect = TRUE;
//Size & Shape
sizeInterpolation = TRUE;
startSize = <0, 0, 0>;
endSize = <2, 2, 0.0>;
followVelocity = TRUE;
texture = "Water Particle 4";
//Timing
particleLife = 1.5;
SystemLife = 0.0;
emissionRate = 0.0;
partPerEmission = 20;
//Emission Pattern
radius = 0.01;
innerAngle = 0;
outerAngle = 4;
omega = <0, 0, 0>;
pattern = PSYS_SRC_PATTERN_EXPLODE;
// Drop parcles at the container objects' center
// PSYS_SRC_PATTERN_DROP;
// Burst pattern originating at objects' center
// PSYS_SRC_PATTERN_EXPLODE;
// Use 2D angle between innerAngle and outerAngle
// PSYS_SRC_PATTERN_ANGLE;
// Use 3D cone spread between innerAngle and outerAngle
// PSYS_SRC_PATTERN_ANGLE_CONE;
//Movement
minSpeed = 0.1;
maxSpeed = .2;
acceleration = <2, 0, -1.5>;
windEffect = FALSE;
bounceEffect = FALSE;
followSource = FALSE;
target = "";
// llGetKey() targets this script's container object
// llGetOwner() targets the owner of this script
//Particle Call
setParticles();
}

default
{
state_entry()
{
}
link_message( integer sender, integer num, string message, key id )
{
if( num == 0 ) //turns off the particle system when the number 0 is transmitted
{
running=TRUE;
llSetText(" ", <0.0, 1.0, 0.0>, 0.5);
llParticleSystem([]);
}

else
{
running=FALSE;
llSetText(" ", <0.0, 1.0, 0.0>, 0.5);
ParticleFallsEffect();
}

}
}
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
11-06-2005 01:14
This is a recurring problem, see these threads:
/54/0f/67025/1.html
/54/b8/67679/1.html
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Sol Columbia
Ding! Level up
Join date: 24 Sep 2005
Posts: 91
11-07-2005 10:26
I'd change it to PSYS_SRC_PATTERN_ANGLE_CONE with inner and outer angles of 0 to get the particles traveling along a linear path.

If your particles are streaming upward or in some weird direction after changing from explode to cone, I would suggest adding the script to a transparent prim embedded in the tip of the gun (as opposed to the gun itself). You can rotate this invisible prim to get the particles going in the right direction since the push vector is global as you've discovered.

Hope this helps!
-Sol
Xantor Welesa
Registered User
Join date: 16 Jun 2005
Posts: 18
11-07-2005 10:47
And set followsource to TRUE...

*X*