Constraining a locator to particle [0]


#1

So I needed to constrain a locator to a moving particle so that I can bake the translation of the particle into it and get some animation curves. So far, I found this information in a previous thread:

—— start of previous message

Parv
Frequenter Jul '12
Well…
This works with regular particles so not sure if it will work with nParticles or not.

// declare a float array variable and store the world position values of a particle in it

float $position[] : getParticleAttr worldPosition -at particleShape1.pt[1];

//assign the stored values to the Translate X Y Z attributes of the locator

locator1.tx = $position[0];
locator1.ty = $position[1];
locator1.tz = $position[2];

// I hope it helps

—— end of precious message

However, I tried it and it gives me a ton of syntax errors. Needed to know if anyone knows what I could be doing wrong.

I tied it with particleShape1.pt[0] as well as with particle1.pt[0] and particle1.pt[1]. I also tried it with both nParticles and regular particles.

But I get syntax errors for every line almost. Any help would be appreciated to get this to work or another way to constrain the locator and make this work.

Thanks in advance,

Ken


#2

The following expression should do what you want:

vector $pos[] = `getAttr nParticleShape1.position`;
vector $p = $pos[0];
locator1.translateX = $p.x;
locator1.translateY = $p.y;
locator1.translateZ = $p.z;

Note that this assumes particles are not dying, in which case the index in the array can change… one needs to to then use the particleid to match between frames.