+2 votes

Basically subj. It's almost a duplicate of this question https://godotengine.org/qa/32039/create-particles2d-that-radiates-particles-every-direction
But the accepted solution emits particles in random directions.

Godot version 3.3.2
in Engine by (17 points)

I also wanted to do this so I tried converting the particle material to a particle shader and editing the shader. I haven't done anything with shaders before so this might not be proper but it is what I have so far.

In order to spread the particles out evenly the shader would have to know the amount of particles. This doesn't seem to be available in the vertex buffer (?) so I resorted to passing the shader a uniform value

uniform float initial_particle_amount; // added this

but I have to set that value manually or with a script.
Then I replaced the line

float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;


float angle1_rad = (float(INDEX) * (spread_rad / (initial_particle_amount / 2.0)));

and that emitted the particles in and even spread.

I noticed there is a initialanglerandom value but I don't understand what it does. Ideally we would be able to set a value between 0 and 1 to control the "randomness" of the particle spread.

1 Answer

+1 vote
Best answer

You can convert particle material to particle shader, and there override direction/velocity code. You will have to write similar function to what You would do in Godot - iterate through angles of circle and assign direction within chosen intervals. You will have to learn shader language tho. Try to come up with something and post Your result here, I will try to correct You.

by (5,649 points)
selected by

Thanks! I already tried it with shaders but couldn't find a way to get the particle's number then (since explosiveness may be 100%). Just needed to RTFM. :/ There are two. NUMBER and INDEX. So, replace

float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;


float angle1_rad = fract(float(NUMBER) * angle_step) * spread_rad;

Where angle_step is a uniform float. And this would be the first time I successfully tinkered with shaders.

For anyone finding this question later, TFM is here: https://docs.godotengine.org/en/stable/tutorials/shading/shading_reference/particle_shader.html

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.