Hi everyone, I have 2 sphere mesh, one usd to emit particles, the other one used to define postionTargets, i apply a set velocity based on normalized vector and all goes well.
What i need is to funnel the particles in a virtual “tunnel” around the vector which connect the 2 spheres, defining a spline to decide where this force is active and when it stop to “compress” particles around the vector connecting the meshes.
I tried several approaches, starting fromthe idea to find for each particle the force to apply using its projection on the connecting vector…still cant get out of it
Basically I need something like the attached sketch…any hints ? Thank you in advance
Morning. They are plenty of ways of obtaining this funneling effect. I gave it a try and here is the solution that gave me the closest results while still being pretty easy to manipulate.
The idea is relatively simple:
Generate a Random Position on the Target Sphere and store it.
Spawn Particles on the Source Sphere Surface.
Create two colliders: for the Source and Target Sphere.
Create a line attractor between the Source Sphere and Target Sphere positions.
Create a Target Position force attractor.
Modulate the force based on the Distance to the Target Sphere.
Sphere property:
First, I’m creating two sphere property (Source and Target). From here, I’m using the VFX property binder script to bind them to the sphere in my scene.
For this, I’m using the Set Position Shape Sphere. I’m only using the Radius of my Target Sphere.
But I’m not using the transform, as this Target Positon will be updated every frame thanks to the Target Sphere Transform. This position is then stored in a “TargetPosition” Attribute":
Initial Position:
With the Target Position properly stored, we can now set our particle position to our Source sphere.
I’m using another Set Position Shape Sphere. This time, I’m using the Sphere Source property fully.
In the Update context, we’ll add create a Target position force. For this we need to update the target position each frame. For this, I’m using a Transform Position operator using the stored Target Position attribute and the Sphere Target transform.
We can subtract to this our Current Particle’s position. This will give us a vector that points toward the Target position. This vector is then normalized and multiplied by a strength parameter.
Line Attractor:
To create the funneling, we want to attract our particles to the line between our two spheres.
We first can use the “Distance Line” operator:
Thanks to the ClosestPosition Output, we can subtract it to our current particle position to get a vector that points toward our Line. This gives us the Line Attractor vector that can normalize and multiply by a strength value:
Force Modulation:
Both forces are added together, but we still need to modulate the line attraction. We want to control when they are attracted by the line and when we would like to release this attraction.
For this, we’re computing the distance between our current particle position and the Target Sphere. This distance is then remapped between 0-1 by dividing it by the distance between our two sphere.
Here’s a small unity package that you can import into your project. It should work with any Unity6 version and above. VFXG_SphereAttractor_Funnel.unitypackage (18.3 KB)
I hope this will help you to get what you’re looking for. Have a lovely day.
First of all, thank you so much for your time—I truly appreciate it.
I studied the entire process following your approach, and the most important takeaway for me is that I learned about elements I never even imagined I could use, such as custom attributes. These attributes can essentially be reused to manage every aspect of the VFX, which really resonates with the way I think (since I’m a coder). I just didn’t know how to approach this within the node editor before.
I will now continue refining the VFX, studying all the steps you described. I was focusing on velocity rather than force, and with your detailed description, I’m able to test different “variants” step by step. Thank you for the help, but more importantly, for explaining why and how—it’s a very valuable lesson!