Indeed you could use spatial layers to achieve this kind of dynamic behavior.
In the Content example project that you can download with the plugin, there is a PopcornFX project that comes with it containing various effects including a butterfly cannon / attractor duo:
- Pk_ButterflyAttractor.pkfx (Invisible particles in space having repelling or attracting force)
- Pk_ButterflyCanon.pkfx (Dynamic butterflys reacting to those repelling forces)
Even though the butterfly behaviors are quite complex, you could study those FXs to understand how you could do it but basically:
- Invisible butterfly attractor particles inject themselves inside a ButterflyAttractor spatial layer
- Dynamic butterfly particles "sample" this spatial layer to query neighbor particles asking for the closest attractor, and collect their "Attractor" field from them (which contains the attractor position and the attractor force as a float4 field)
- If it finds an attractor it will compute an additional force based on the distance with the attractor and the attractor forces (can be negative to give repelling force)
- If it doesn't find anything the butterfly continue its life
I'll include screenshots so to highlight the most important points in those effects
This is the spatial insertion for invisible attractor particles
Here is the actual usage (in Pk_ButterflyCanon.pkfx) of this spatial layer, basically saying "Do I have a nearby attractor in 15 units nearby my position ? If yes add some corresponding force to use that later do change my velocity.
Some useful links including other ways to achieve attractor behavior:
To conclude there are different ways you could do it, but in terms of fully dynamic behavior and control you should go with spatial layers :)
Hope this helps.