Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (SBGuy), 712 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Multiple Particle Movement #360579
02/25/11 03:19
02/25/11 03:19
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
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

Re: Multiple Particle Movement [Re: Valdsator] #360580
02/25/11 03:34
02/25/11 03:34
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline
Serious User
darkinferno  Offline
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
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
}

Re: Multiple Particle Movement [Re: darkinferno] #360581
02/25/11 04:05
02/25/11 04:05
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
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

Re: Multiple Particle Movement [Re: Valdsator] #360607
02/25/11 11:32
02/25/11 11:32
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
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


Hilf mir, dir zu helfen!
Re: Multiple Particle Movement [Re: hopfel] #360619
02/25/11 14:27
02/25/11 14:27
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
Awesome! I modified it a bit, and it works perfectly.

Thanks. laugh


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1