0 votes
force += length(diff) > 0.0 ? normalize(diff) *....

This is the type of syntax which You can see in Godots default particle shader.

How do You read this ? How can You mix boolean within float calculations ?

in Engine by (8,097 points)

1 Answer

0 votes
Best answer

This is ternary if operator. Basically this is shorthand for if ... then ... else ...
So if your statement is true, then instructions between ? and : are executed. If statement is false, then instructions after : and until line end are executed.

In your case this code can be rewritten as

  if length(diff) > 0.0:
    force += normalize(diff) * ...
  else:
     ...
by (1,650 points)
selected by
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.