+2 votes

I would like to assign random values to theta in order to stagger sinusoidal motion randomly at instantiation:


func _ready():


shader_type canvas_item;
uniform float theta : hint_range(0.0,3.1415);

void vertex() {
        VERTEX.x += 20.0*sin((TIME+theta)*2.0);

but the nodes are instantiated all with the same value. Can anyone help with this?

Thank you in advance.

in Engine by (19 points)

2 Answers

+5 votes
Best answer

Your nodes all use the same ShaderMaterial. So when you modify one, you actually modify the same all the time, so all nodes end up the same.

If you want your nodes to use the same shader but have different parameters, you need to make them unique:

material = material.duplicate()
material.set_shader_param("theta", randf() * PI)
by (28,886 points)
selected by

If I had forgotten, I think that checking in the inspector resource> Local to Scene is the same.

This is a great work around. Thank you.

+1 vote

It is good that it is so, it is by depuration. To have a new random value each time use this function in _ready (): randomize ()

by (2,236 points)
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 Frequently asked questions and 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 [email protected] with your username.