Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need Help with Particle Script

Keno Pontoppidan
Registered User
Join date: 20 Oct 2005
Posts: 75
10-22-2005 17:37
Another problem of mine. Ok im making a vehicle and I want to use this particle script with the engines but the particles are always facing the same way they dont turn with the ship, please help. This is the script

CODE

// Particle Script 0.3
// Created by Ama Omega
// 10-10-2003
// Interactive Dev Kit version by Cienna Rand
integer lHandle = -1;
integer run = 1;

// Mask Flags - set to TRUE to enable
integer glow = TRUE;
integer bounce = FALSE;
integer interpColor = TRUE;
integer interpSize = TRUE;
integer wind = FALSE;
integer followSource = TRUE;
integer followVel = FALSE;
integer pattern = PSYS_SRC_PATTERN_ANGLE_CONE;
key target = "";
float age = 3.5;
float maxSpeed = 0.0;
float minSpeed = 0.0;
string texture;
float startAlpha = 1;
float endAlpha = 0.1;
vector startColor = <1,2,0>;
vector endColor = <1,0,0>;
vector startSize = <1.5,1.5,1.5>;
vector endSize = <0.1,0.1,0.1>;
vector push = <0,1,0>;

float rate = 0.1;
float radius = 0;
integer count = 3;
float outerAngle = 0;
float innerAngle = 0;
vector omega = <0,0,20>;
float life = 0;

integer flags;

updateParticles()
{
flags = 0;
if (target == "owner") target = llGetOwner();
if (target == "self") target = llGetKey();
if (glow) flags = flags | PSYS_PART_EMISSIVE_MASK;
//if (bounce) flags = flags | PSYS_PART_BOUNCE_MASK;
if (interpColor) flags = flags | PSYS_PART_INTERP_COLOR_MASK;
if (interpSize) flags = flags | PSYS_PART_INTERP_SCALE_MASK;
//if (wind) flags = flags | PSYS_PART_WIND_MASK;
if (followSource) flags = flags | PSYS_PART_FOLLOW_SRC_MASK;
if (followVel) flags = flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
//if (target != "") flags = flags | PSYS_PART_TARGET_POS_MASK;

llParticleSystem([ PSYS_PART_MAX_AGE,age,
PSYS_PART_FLAGS,flags,
PSYS_PART_START_COLOR, startColor,
PSYS_PART_END_COLOR, endColor,
PSYS_PART_START_SCALE,startSize,
PSYS_PART_END_SCALE,endSize,
PSYS_SRC_PATTERN, pattern,
PSYS_SRC_BURST_RATE,rate,
PSYS_SRC_ACCEL, push,
PSYS_SRC_BURST_PART_COUNT,count,
PSYS_SRC_BURST_RADIUS,radius,
PSYS_SRC_BURST_SPEED_MIN,minSpeed,
PSYS_SRC_BURST_SPEED_MAX,maxSpeed,
PSYS_SRC_TARGET_KEY,target,
PSYS_SRC_INNERANGLE,innerAngle,
PSYS_SRC_OUTERANGLE,outerAngle,
PSYS_SRC_OMEGA, omega,
PSYS_SRC_MAX_AGE, life,
PSYS_SRC_TEXTURE, texture,
PSYS_PART_START_ALPHA, startAlpha,
PSYS_PART_END_ALPHA, endAlpha
]);
}

processFlag(string var)
{
integer type;
string c = llGetSubString(var, 0, 0);
if (c == "+") type = TRUE;
else if (c == "-") type = FALSE;
else return;
string v = llToLower(llGetSubString(var, 1, llStringLength(var)));
if (v == "glow") glow = type;
else if (v == "bounce") bounce = type;
else if (v == "interpcolor") interpColor = type;
else if (v == "interpsize") interpSize = type;
else if (v == "wind") wind = type;
else if (v == "followsource") followSource = type;
else if (v == "followvel") followVel = type;
updateParticles();
}

processPattern(string var)
{
string v = llToUpper(var);
if (v == "EXPLODE")
pattern = PSYS_SRC_PATTERN_EXPLODE;
else if (v == "DROP")
pattern = PSYS_SRC_PATTERN_DROP;
else if (v == "ANGLE_CONE_EMPTY")
pattern = PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY;
else if (v == "ANGLE_CONE")
pattern = PSYS_SRC_PATTERN_ANGLE_CONE;
else if (v == "ANGLE")
pattern = PSYS_SRC_PATTERN_ANGLE;
else return;
updateParticles();
}

showSetFlags()
{
list f = [];
if (glow) f += ["GLOW"];
if (bounce) f += ["BOUNCE"];
if (interpColor) f += ["INTERP_COLOR"];
if (interpSize) f += ["INTERP_SIZE"];
if (wind) f += ["WIND"];
if (followSource) f += ["FOLLOW_SOURCE"];
if (followVel) f += ["FOLLOW_VEL"];
llWhisper(0, "Set: " + llList2CSV(f));
}

showPattern()
{
if (pattern == PSYS_SRC_PATTERN_EXPLODE)
llWhisper(0, "Pattern: EXPLODE");
else if (pattern == PSYS_SRC_PATTERN_DROP)
llWhisper(0, "Pattern: DROP");
else if (pattern == PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY)
llWhisper(0, "Pattern: ANGLE_CONE_EMPTY");
else if (pattern == PSYS_SRC_PATTERN_ANGLE_CONE)
llWhisper(0, "Pattern: ANGLE_CONE");
else if (pattern == PSYS_SRC_PATTERN_ANGLE)
llWhisper(0, "Pattern: ANGLE");
}

vector string2vector(string s)
{
list foo = llCSV2List(s);
vector v;
v.x = llList2Float(foo,0);
v.y = llList2Float(foo,1);
v.z = llList2Float(foo,2);
return v;
}

float fixColor(integer c)
{
if (c > 255) return 255;
if (c <= 0) return 0;
return (float)c/255;
}

vector colorVector(string s)
{
list foo = llCSV2List(s);
vector v;
v.x = fixColor(llList2Integer(foo,0));
v.y = fixColor(llList2Integer(foo,1));
v.z = fixColor(llList2Integer(foo,2));
//llWhisper(0, "Debug: v: " + (string)v);
return v;
}

dumpParams()
{
llWhisper(0, "PART_MAX_AGE:" + (string)age);
llWhisper(0, "PART_FLAGS:" + (string)flags);
llWhisper(0, "PART_START_COLOR:" + (string)startColor);
llWhisper(0, "PART_END_COLOR:" + (string)endColor);
llWhisper(0, "PART_START_SCALE:" + (string)startSize);
llWhisper(0, "PART_END_SCALE:" + (string)endSize);
llWhisper(0, "SRC_PATTERN:" + (string)pattern);
llWhisper(0, "SRC_BURST_RATE:" + (string)rate);
llWhisper(0, "SRC_ACCEL:" + (string)push);
llWhisper(0, "SRC_BURST_PART_COUNT:" + (string)count);
llWhisper(0, "SRC_BURST_RADIUS:" + (string)radius);
llWhisper(0, "SRC_BURST_SPEED_MIN:" + (string)minSpeed);
llWhisper(0, "SRC_BURST_SPEED_MAX:" + (string)maxSpeed);
llWhisper(0, "SRC_TARGET_KEY:" + (string)target);
llWhisper(0, "SRC_INNERANGLE:" + (string)innerAngle);
llWhisper(0, "SRC_OUTERANGLE:" + (string)outerAngle);
llWhisper(0, "SRC_OMEGA:" + (string)omega);
llWhisper(0, "SRC_MAX_AGE:" + (string)life);
llWhisper(0, "SRC_TEXTURE:" + (string)texture);
llWhisper(0, "PART_START_ALPHA:" + (string)startAlpha);
llWhisper(0, "PART_END_ALPHA:" + (string)endAlpha);
}

default
{
state_entry()
{
if (lHandle == -1) lHandle = llListen(0, "", llGetOwner(), "");
else {
llListenRemove(lHandle);
lHandle = llListen(0, "", llGetOwner(), "");
}
updateParticles();
}

touch(integer num_deteced)
{
if (run == 1) {
run *= -1;
llParticleSystem([]);
} else {
run *= -1;
updateParticles();
}
}

listen(integer channel, string name, key id, string msg)
{
list argv = llParseString2List(msg, [" "], []);
integer argc = llGetListLength(argv);
string cmd = llToLower(llList2String(argv, 0));
if (cmd == "set")
{
if (argc == 1) showSetFlags();
else processFlag(llList2String(argv, 1));
}
else if (cmd == "pattern")
{
if (argc == 1) showPattern();
else processPattern(llList2String(argv, 1));
}
else if (cmd == "target")
{
target = llList2String(argv, 1);
if (target == "none") target = "";
updateParticles();
}
else if (cmd == "age")
{
age = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "maxspeed")
{
maxSpeed = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "minspeed")
{
minSpeed = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "startalpha")
{
startAlpha = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "endalpha")
{
endAlpha = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "startcolor")
{
startColor = colorVector(llList2String(argv, 1));
updateParticles();
}
else if (cmd == "endcolor")
{
endColor = colorVector(llList2String(argv, 1));
updateParticles();
}
else if (cmd == "startsize")
{
startSize = string2vector(llList2String(argv, 1));
updateParticles();
}
else if (cmd == "endsize")
{
endSize = string2vector(llList2String(argv, 1));
updateParticles();
}
else if (cmd == "push")
{
push = string2vector(llList2String(argv, 1));
updateParticles();
}
else if (cmd == "omega")
{
omega = string2vector(llList2String(argv, 1));
updateParticles();
}
else if (cmd == "rate")
{
rate = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "radius")
{
radius = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "count")
{
count = llList2Integer(argv, 1);
updateParticles();
}
else if (cmd == "outerangle")
{
outerAngle = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "innerangle")
{
innerAngle = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "life")
{
life = llList2Float(argv, 1);
updateParticles();
}
else if (cmd == "on")
{
updateParticles();
}
else if (cmd == "off")
{
llParticleSystem([]);
}
else if (cmd == "dump")
{
dumpParams();
}
}
}
Torley Linden
Enlightenment!
Join date: 15 Sep 2004
Posts: 16,530
10-22-2005 17:39
One general problem with that is you're using an old version of the particle script... go to Particle Laboratory @ Teal (202, 50) up in the sky and bag yourself the newest one. It has very helpful commentary to explain what each parameter does, including the turns you mention. You can learn a lot better, easier this way. :)
_____________________
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
10-23-2005 03:06
these interactive scripts are great for playing around with different options to work out how your particles should look - but in your final script you will find that it is a hell of a lot easier to use llParticleSystem directly (it's also completely lag free!)

example:
CODE
default
{
state_entry()
{
llParticleSystem([
PSYS_PART_MAX_AGE, 3.5,
PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK | PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK | PSYS_PART_FOLLOW_SRC_MASK,
PSYS_PART_START_COLOR, <1,2,0>,
PSYS_PART_END_COLOR, <1,0,0>,
PSYS_PART_START_SCALE, <1.5,1.5,1.5>,
PSYS_PART_END_SCALE, <0.1,0.1,0.1>,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE_CONE,
PSYS_SRC_BURST_RATE, 0.1,
PSYS_SRC_ACCEL, <0,1,0>,
PSYS_SRC_BURST_PART_COUNT, 3,
PSYS_SRC_BURST_RADIUS, 0.0,
PSYS_SRC_OMEGA, <0,0,20>,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_PART_START_ALPHA, 1.0,
PSYS_PART_END_ALPHA, 0.1
]);
}
}

you should find this much easier to understand and update.
Keno Pontoppidan
Registered User
Join date: 20 Oct 2005
Posts: 75
10-23-2005 07:52
Lol i know how to do most the other stuff like how to change color and stuff I just wanted to know why the particles dont turn they always comeout facing the same direction.
Xantor Welesa
Registered User
Join date: 16 Jun 2005
Posts: 18
10-23-2005 09:07
That's an inherent limitation of the particle system. It uses the 'billboard' feature on your video hardware to render a 2d texture at the right z-offset only, so it's not a real 3d-object.

Advantage: REAL fast
Disadvantage: Seems like it always faces you directly. (Can make for nice effects though, think advertisements :) )

*X*
Ushuaia Tokugawa
Nobody of Consequence
Join date: 22 Mar 2005
Posts: 268
10-23-2005 11:25
Set push (PSYS_SRC_ACCEL) to ZERO_VECTOR

Set maxSpeed and minSpeed (PSYS_SRC_BURST_SPEED_MIN and PSYS_SRC_BURST_SPEED_MAX) both to 1.0

Set omega (PSYS_SRC_OMEGA) to ZERO_VECTOR

You will have to adjust your particle emiting prim to where the Z axis points in the direction you want the particles to flow.

Note: the script you are using is outdated and is using some deprecated constants (PSYS_SRC_INNERANGLE and PSYS_SRC_OUTERANGLE). I would suggest using a new version or simply inputting the particle system by hand rather than keeping this script in your production version.
_____________________
Zalandria Zaius
Registered User
Join date: 17 Jan 2004
Posts: 277
particle push
10-23-2005 19:27
vector push = <0,1,0>;

This is probably why your particles keep going the same way.. I think that push is global if I recall right.. Meaning it will always push them to the worlds Y coords set like that.
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
10-24-2005 01:56
Yes, the acceleration applied to particles is global, and doesn't turn with the vehicles. You should use burst speeds instead (these turn with the vehicle). I suggest using a CONE_ANGLE pattern with an ANGLE_BEGIN of 0.0 and an ANGLE_END of 0.05 (so the particles comme out of one end of the prim), and burst speeds of 1.5 to 2.5, with a push of <0,0,0.2> to make engine's smoke rise slowly.
_____________________
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.