Set Particle Parameter in Blueprint by Camera Distance

Hi, I like to set the particle opacity by camera distance in blueprint.
I set up this blueprint so far, but it won’t work.

There must be an error in the vector math of the cam distance formula, since when i make a literal float, i can see, the parameter connection works.
0 brings 0 opacity and 1 brings a lit particle ingame.

but when i connect the vector stuff, the particle stays at 0 opacity :frowning:
can you help me out?

Use a subtraction instead of a division.

Let’s say you have the camera and the actor at [1,1,1] and [3,3,3].
If you now subtract your camera from your actor you’re left with [-2,-2,-2] which is a defined length and will provide you with the result you want.

However vector division is mathematically only possible if you provide special input and I’m not sure what unreal is doing inside of that node.

Here’s a link to a discussion about vector division if you’re interested.

Regardless of this though division only tells you how often the lower one fits into the upper part meaning you will never really get a useful number if you’re searching for distance or anything like that.

ah sure! my fault. it should have been a subtraction. or better: it was one, but i fiddled with the graph and deleted it once, and then somehow took division when i remodeled it.
this is also the reason, why i saw my particle half the day, and then suddenly no more.

anyway, when i subtract it, the particle can be seen again, but it is always visible.
but it should fade, when i come close to it.

which let me assume that the result is far beyond 1, or the resulting distance is mapped in a weird way to 0-1.
do you have a clue how to normalize in a proper way? a simple clamp won’t do it either.

i believe i have to divide the vector length float with the maximum distance of “1” being located away from the actor?
hmm, can you understand what i mean? haha… i tried that, but it didn’t work.

concerning the link.

i was out after the second answer…unfortunately :frowning:

Well I did not get all of it but I think I know your problem.

The thing is the lengh of this path is always several hundred. One unit represents 1 cm if I recall correctly so yea…

The easiest solution I can come up with would be dividing the result from “Vector Length” by the distance you want and subtracting 1 so it will be 0 if it’s exactly the distance, negative if it’s lower (which will be normalized to 0) and then become slowly more until it is capped at the doubled distance which you divided by. At that distance it will be 1.

I’m currently not at home and can look for a proper solution. Give me until this evening for that :slight_smile:

thx erasio,

your last addition solved the problem.
this worked. although i altered the “size by life” particle module instead of the opacity since this fits better.
thank you very much!

greetings!

Awesome. I would’ve looked into another way now but well. More time for series this evening for me ;D

Please check the “Accept this Answer” button at the very first answer I gave so others know as well that this is solved. Otherwise someone will most likely come back to this post and he/she will probably not read through everything we wrote here so they will just answer as well. :wink:

sir, the deed is done. :slight_smile:
thx again!

You can do this work in the material…

thank you homerye! this is a very useful tutorial series! i didn’t know about the sphere mask either. however in my latest example i modified the particle size in the end. is this also possible to do in a material? perhaps by modifying the world pos offset or so?

Yes, you should be able to do this with WPO.

I am not in front of the editor at this moment, I believe there is a material function that will do this for you. Try searching for distance scaling or scaling in the material editor.