Nparticle RadiusPP relative to another object


#1

Hi,

I’m trying to change the RadiusPP on an nParticle with respect to another object through a RadiusPP expression.

For example, let’s say I have a locator at the origin, and particles closer to it are large and get smaller as they get further away.

Any help?


#2

Something like this in Runtime before dynamics:

vector $pos = position;
float $dist = mag($pos);
nParticleShape1.radiusPP += $dist/200;

#3

Thanks - but, how do you measure the distance to each particle? It feels like I should put them in an array and measure to each one - is that true? If so, I thought to use the filterxpand command, but it has no nPartcile index.


#4

The distance is the magnitude of the world position of each particles. Like you said you need to get particles distance from origin.


#5

Ah - that makes sense - alright - it works nicely. Thanks for this.

I do have two follow up questions.

  1. How do I reverse the effect (larger when it is closer to the origin) - I tried making a new value of 1/$dist, but that seems to not work - I thought I was being logical but maybe I’m wrong.

  2. How do we tackle the issue when it is not in the origin - a distance to another object or locator?

Thanks again


#6

You can get the distance by subtracting one point from the other and taking the magnitude of the result. So one could define a new point instead of the origin:

vector $pos = position;
vector $center = <<0,5,0>>;
float $dist = mag($pos-$center);

If you used the following:

nParticleShape1.radiusPP = 1.0/$dist;

Then the particles will be infinitely big at the center point, 1.0 when 1 unit away, and then gradually fall off to zero radius at infinite distance. If instead you want a linear dropoff with distance then you should define what distance beyond which the radius becomes zero:

float $maxDist = 20.0;
if ($dist < $maxDist ){
   nParticleShape1.radiusPP = $maxDist -$dist;
} else {
  nParticleShape1.radiusPP = 0;
}