Multiple Particle Movement

Posted By: Valdsator

Multiple Particle Movement - 02/25/11 03:19

I'm making a particle effect at the moment where when an enemy dies they spawn about 20 particles, and I want every one to move in a random direction.

The only way I can do this at the moment is to copy and paste this command 20 times:
Code:
effect(blood,1,vector(my.x,my.y,my.z),vector(random(40)-20,random(40)-20,5));


But, I would like to do something like this.
Code:
effect(blood,20,vector(my.x,my.y,my.z),vector(random(40)-20,random(40)-20,5));


This code spawns 20 particles with one command, but it only randomly generates an x velocity and y velocity once, so all those 20 particles move in the exact same direction.

I've messed around with the "blood" function that I have for the particles, trying to set vel_x and vel_y to a random number (which results in the particles spazzing out and moving in random directions every frame), and trying out other methods, but none have worked.

So, how do I spawn 20 particles with one line of code, and have every particle move in a different direction, without the direction changing every frame?

Thanks to anyone who tries to help. I'm a noob. :3
Posted By: darkinferno

Re: Multiple Particle Movement - 02/25/11 03:34

function bloodfade(PARTICLE *p)
{
p.alpha -= 20*time_step;

if (p.alpha <= 0)
{
p.lifespan = 0;
}
}

function blood(PARTICLE *p)
{

p.bmap = bloodbmap;

p.vel_x+=random(10)-random(10);
p.vel_y+=random(10)-random(10);
p.vel_z-=random(10)-random(10);

p.size=random(4);
p.alpha = 100;
p.flags |= ( MOVE | TRANSLUCENT );
p.event = bloodfade; // change to a shorter, faster function
}
Posted By: Valdsator

Re: Multiple Particle Movement - 02/25/11 04:05

Hm, not exactly what I wanted. Here's a picture. The "Bad" part is what I'm getting at the moment (and what I got before when I experimented). The "Good" part is what I want, and can accomplish by copy and pasting the effect code over and over again. I don't want every particle to go in a random direction every frame, but choose a direction when they spawn, and go towards that direction for it's whole lifespan, while also being pulled down by gravity.



Thanks. laugh
Posted By: hopfel

Re: Multiple Particle Movement - 02/25/11 11:32

Ok, I made something like this a view months ago...
I'm sure there's a smarter way, but this works also:

Code:
function exploevent(PARTICLE *p)
{
p.x+=p.skill_b*time_step;  
p.y+=p.skill_c*time_step;  
p.z+=p.skill_d*time_step;
}

function pef(PARTICLE *p)
{
p.lifespan=100;
p.alpha =100;
p.size=2;
p.bmap = dreckp; 
p.flags |= TRANSLUCENT | BRIGHT | MOVE;
p.event=exploevent;
if(p.skill_a==0)
{
p.skill_b=random(40)-20;
p.skill_c=random(40)-20;
p.skill_d=random(40)-20;
p.skill_a=1;
}}



This makes a firework, but the particels hold their direction. laugh
Hope I helped you a bit. ^^
~greets
Posted By: Valdsator

Re: Multiple Particle Movement - 02/25/11 14:27

Awesome! I modified it a bit, and it works perfectly.

Thanks. laugh
© 2024 lite-C Forums