Spawn particles only if the containing object is moving forward

Hi, I’m not sure it is possible, but I’m trying to spawn particles based on movement but only forwards.
I already tried Spawn Over Distance which is great but it gives me particles also if the object is moving backwards(-Z).

Is there a way in VFX graph to get the previous position?

Anyone has an idea?

There is oldPosition. Also this thread might be helpful if you want custom spawning logic:

Morning
So as @Qriva mentioned, the link post will help you get the First-part of your problem.
The “SpawnoverDistance” Block is working fine, but some “garbage” is created so for performance reason, I suggest that you use the Solution described in the Post . The performance issue should be addressed and you can track it here.

Now regarding the second part : Only spawning when moving forward , here’s a simple Solution.

The idea is to get, the Local “Velocity” of the Gameobject. This way you should be able to get the Axis that you’re interested in (Z from what you said) and just check if it’s Positive or Not.
Will then we able to modulate our SpawnRate based on this Sign.

Here’s my try:

I’m using the SpawnOver distance described in the Linked Post.
The velocity is plugged in a “ChangeSpace” Block (Vector). This way get the LocalVelocity. Be sure that your “ChangeSpace” block is is set to “Vector” and that the “TargetSpace” is local.

From here , we’re gonna use a Dot Product to compare our Local Velocity Vector with our Direction.
In this case as you asked, the local Forward Z (0,0,1). If you’re not familiar with Dot Product, I would suggest that you look at this Video from Freya Holmér or even this simple and Visual Explanation.
To be quick, the result of the Dot should give us a scalar between -1<>1 . So, Positive Results when, the Local Vel is aligned with our Z-Forward, 0, when the vectors are Perpendicular, and Negative when the Vector going in opposed direction.

I’m multiplying the Dot result by a very big number and Saturate the result (clamp between 0-1).
With this I can use it to multiply my “spawn Rate” resulting in a system Spawning particles when moving on the Z-Forward:

Note that The Dot Product has been used so that you can easily Change the direction you want to compare.
An example with the Positive XAxis:

If you’re sure that you want to Forward-Z, just using a “sign” and Saturate should work.

Hope you’ll find this helpfull.
Have a great day.

3 Likes