0 votes

Hello,

I'm trying to create a speed effect with "after-images" of the player. I'd like to use particles for this. The player is a 2D sprite, top-down view, and obviously rotates while moving. So each emitted particle should have the same rotation as the player. However, I can't seem to be able to do that.
The particles are set to NOT use local coordinates (they're supposed to be left behind by the player like footsteps, basically).
I tried manipulating the "angle" property of the process material, but that rotates ALL particles currently on the screen.
I tried rotating the Particle2D node itself, but that doesn't do anything.

Does anyone have an idea how to do this (preferably in Godot Script).

Godot version 3.3.3
in Engine by (31 points)
edited by

Okay, so I gave up on the particle thing. It kinda felt like every idea I had (from rotating sprites to swapping sprites on the fly), the devs had forseen and actively prevented it. Godot does have a couple of strange decisions in there, this just seems to be one of them.
I decided to create a trail effect using the Line2D node instead. It's not exactly the look I wanted, but it's a helluva lot better than creating a trail out of a couple dozen sprites. It might be feasible to do that but I just don't like the idea.
Here's hoping that they'll add some more flexibility to particles in future versions.

1 Answer

0 votes
Best answer

Convert the process material to a shader material. Modify the following:

1)

uniform float initial_linear_velocity;
uniform float emission_angle; // <<<<<<<<< Add this
uniform float initial_angle;

2) Inside the vertex function, somewhere below if (RESTART || restart) {, change the assignment of CUSTOM.x from base_angle * degree_to_rad to (base_angle + emission_angle) * degree_to_rad

3) In the else bracket following the previous if, find where it says CUSTOM.x = base_angle * degree_to_rad; and change it to CUSTOM.x += base_angle * degree_to_rad;

After the changes are done, you can send the shader an angle parameter by calling $Particles2D.process_material.set_shader_param("emission_angle", your_angle_in_degrees)

I hope this helps :)

by (795 points)
selected by

Hm... I have only just started using Godot and, truth be told, I haven't got the slightest clue what you are talking about. I tried changing the process material from particle material to shader material, but that only resulted in no visible particles at all.
So the first thing I'd need to figure out is how to make anything show up at all.

Also, I couldn't find any of the code you wrote anywhere. Where would that be?

You can convert a particle material to a shader material from the drop down menu:

image

This will make the particle logic editable. Upon conversion, the bottom panel should open the shader code editor.

I found it, and it works! Thank you skysphr!
Incredible how much effort this takes, considering how simple it seems.

Also figured out how make the particles fade over time:
Add another variable uniform float alpha_fade, change line COLOR = hue_rot_mat * color_value; to COLOR = (hue_rot_mat * color_value) - vec4(0, 0, 0, CUSTOM.y * alpha_fade);
I would have NEVER guessed that CUSTOM.x, CUSTOM.y and so on are just random names and do not refer to axis.

Yeah particle shaders and shaders in general are not quite the most documented feature around :P Pretty sure you could have done the alpha fade out without editing the shader though: Go to color, add a gradient texture, set the leftmost color to white, set the rightmost color to transparent.

Nope. I would've done that if it were possible, but the color value is indeed just that. Can't turn it into a gradient.

Sorry, I meant color ramp:

enter image description here

Hm... I can't find it. It may just be me being blind, but the Particle2D's inspector is so convoluted I have severe trouble finding the settings I need. I see there is a "Scale" above the "Color" in your screenshot. I clicked through everything I could find, I have no idea where that might be. The only "Scale" I find is under "Transform" and there's no "Color" there.
I know I can do this if I use a ParticlesMaterial, but nowhere in the ShaderMaterial can I find any way to introduce a GradientTexture, aside from when I add a CanvasItemMaterial under "Material". However, whatever I do there doesn't seem to do anything.
Well, honestly, I'm done with this. I spent a week's worth of evenings trying to figure this out, it works now, quite well actually (in no small part thanks to you), so I'm not going to try and touch it again.
I hear the particle system in Godot 4 is going to see some significant improvement over Godot 3, so here's hoping for that. Because right now I don't feel like touching these again.

Well yeah it only exists there before you convert the material to a shader material. Afterwards, you're in control of everything that particles do. However, using a simple multiplication in the shader the way you did is probably much more optimized for the GPU.

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.