particle refresh delay


#1

I have two particleSystems, s1 has an animated transformNode, the second one (explodeMe) should follow the first one via a runtime expression. I also want to check the distance beween them (there shouldnt be one). I made a custom attributePP (distance) for checking purposes.

// transfer worldPosition of s1 to position of explodeMe
$pos = explodeMeShape.worldPosition; $sPos = s1.worldPosition;
explodeMeShape.position = << $sPos.x, $sPos.y, $sPos.z >>;

// get the distance
explodeMeShape.distX = $sPos.x - $pos.x; explodeMeShape.distY = $sPos.y - $pos.y;
explodeMeShape.distZ = $sPos.z - $pos.z;
$dist = << explodeMeShape.distX, explodeMeShape.distY, explodeMeShape.distZ >>;
explodeMeShape.distance = mag($dist);

When I scrub frame per frame, the distance is never 0. But when I do a refresh on the same frame, the distance changes to 0, as it should! Seemes that the attributes are somehow dirty and dont update correctly.

Has anyone an idea how I could get an immediate refresh of the distance?


#2

In your expression you set the value of the two position variables then set the position on the first particle system. This doesn’t change the value of the variables so when you compute the distance between them it will be the same as if you had computed it before setting the position. So even if the particles are at the same position your print would show them being at different positions.

However they could be at different positions if you used a runtime before dynamics expression. For a position match you want to put this in a runtime after dynamics expression.


#3

Hi Duncan! Thanks a lot for your reply!
Yesterday I took a new attempt and split my expression in before and after. l is the leader system, f the follower…

 [b]runtime before:[/b]
     $sPos = l.worldPosition;     

f.position = << $sPos.x, $sPos.y, $sPos.z >>;

  [b]runtime after:[/b]
 $sPos = l.worldPosition; 

$pos = f.position;

 $distX = $sPos.x - $pos.x;
 $distY = $sPos.y - $pos.y;
 $distZ = $sPos.z - $pos.z;
 $dist = &lt;&lt; $distX, $distY, $distZ &gt;&gt;;

 f.distance = mag($dist);
 
 This did the trick! I now get a correct result - also in the viewport with numeric display of my particles.

#4

Sure, although note that if the velocity for the different particle systems don’t match then the position after dynamics could be different. Thus if you instead set the position in the post dynamics expression it is more guaranteed to exactly match. (what you do depends on the ultimate goal of your simulation)

Also you can simplify things a bit by using vector math:
runtime before:
vector $sPos = l.worldPosition;
f.position = $sPos;

runtime after:
vector $sPos = l.worldPosition;
vector $pos = f.position;
f.distance = mag( $sPos-$pos );


#5

My math is rather rude, so thank you for your suggestions. It makes the expression much easier to read!
The goal of my setup is to trigger parts of the f-particles by the distance. I added a volume force field to the f-particles, that affected a specific region. As soon as the distance is unequal 0, the position transfer from g to f is interupted and another force for the f-particles is triggered.

runtime before:
f.axis_center_magnitude = 0;

runtime after expression:
if (distance != 0){
f.axis_center_magnitude += .2;
}