VFX graph - random direction ( operator)

Hello, I’m new to creating effects. I searched for a solution online but couldn’t find anything. I want to create a “random direction (operator)” within VFX Graph. You can see it at 1:55 in the video I sent. When I type “Random,” I only see “random number (operator random).”

if you watch the next 30 seconds of the video you’ll see that he actually opens the subgraph, showing the node structure. but an easier way is just get 3 random numbers combined into a float3 and normalize it.

1 Like

As @POOKSHANK said, the author is showing how to create a Random Direction Subgraph.
Before Unity 6 Still, as @POOKSHANK and easier method would be to create a Subgraph by using three Random Numbers. P If you install the VFX Graph addition sample, you’ll find a "Random Vector " Operator.

Two things to keep in mind :

  • There’s a difference between Vector3, Vector and Direction:

    • All of them are Vectors.
    • Vector3 has no Space.
    • Vector has a space (Local or World)
    • Direction has a space and is normalized.
  • Random Generation has a seed and can be constant or not. If you create your own Subgraph you can expose some properties to let you drive those Random Generation options.

Now, in Unity6 new you can easily create Random Vector3, Vector2, int … thanks to the update Random operator. So you won’t need to create Subgraph.


A Random Direction can be easily achieved with just a Random Vector3 and a Normalize operator.

I hope this helps a bit. Have a great day.

2 Likes

Something to have into consideration as well is the distribution of the random values.

If you don’t need the distribution to be perfect, the easy method with the random vector3 normalized is good enough. But in that distribution, you will get directions pointing towards the corners more frequently than directions pointing towards the axes. Just imagine a box of some flexible material. To make it into a sphere, you need to push the corners inside, making those areas more dense (and therefore more likely to happen, in this case).

A good but more complicated approach to get a uniform distribution, which is what is used in the video, is to use polar coordinates. Generate 2 random angles, one around a full circle and one around half circle, and use some trigonometry to generate the vector.

You can find a better explanation here, specially slide 11: https://angms.science/doc/RM/randUnitVec.pdf

2 Likes

Wasn’t sure on how to add this explanation correctly. Thanks for those insightful additions @gabriel-delacruz :smiley: