Access particles2d Angle property from code

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ondesic

I have a particle texture that I want to rotate when the player rotates. It seems the only property for doing this is “Angle” under “process_materials”. The problem is I can’t access Angle through code. Is there another way to do it?

:bust_in_silhouette: Reply From: Footurist

Godot’s ParticleEmitter2D is a bit limited in terms of controlling individual control of particles, which means, that setting the random parameters and ramps is about as far as it gets for that, which is enough for a lot of cases though! But in return for that, the engine’s ease of use is undefeated.

However, if you’re fine with that, you can easily access all the parameters of the ParticlesMaterial.

Try this:

var mat = $Particles2D.get_process_material()
mat.angle = 45 / idk right now if it's in radians or degrees
mat.angular_velocity = 3

# setter version
mat.set_angle(45)
mat.set_angular_velocity(3)

I just tried the code but according to code completions, I can’t find a

.get_process_material()

ondesic | 2018-03-20 21:30

Maybe because code completion doesn’t work for references. I’ve encountered some weird exceptions (not meaning the runtime error), but the normal case is it won’t work. Fortunately, Godot has a quickly accessible built-in documentation. Look to the right corner in your script tab and you’ll see the tab “Search help”.

Also, code completion sometimes doesn’t find some functions, idk why, but look at the documentation to find the right functions. I’ve tested what I wrote and it works.

Hope this helps.

Footurist | 2018-03-20 22:04

That’s crazy! It worked. Thank you so much. This function isn’t in the docs at all. I and anyone else with this problem wouldn’t even know this was possible. How do we get this added to the docs and autocomplete?

ondesic | 2018-03-20 23:08

Glad it helped. Well, there’s proably a good reason, why it won’t work with references. Idk for sure, but I assume it’s because of dynamic typing. So, since the reference could be of any data type, the editor is unable to provide proper code completion.

Footurist | 2018-03-21 00:11

Yes, that may be true, but it should be documented at least

ondesic | 2018-03-21 00:21