Constraining a locator to particle [0]


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

Frequenter Jul '12
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[1];

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

locator1.tx = $position[0];
locator1.ty = $position[1]; = $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[0] as well as with[0] and[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,



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.


Thanks Duncan, Is there away to do the same but for the rotation of the particle? Ive tried velocity but the rotations are in very small increments.

I have some Instanced geo on the particles set to rotate using the particles velocity, i was hoping i could add those rotations to the locator as well. Would that rotation data be in the particle itself?

The locator will control ships for a massive space battle.


Yes you should be able to get your rotation per particle property( or whatever name you are using ) in the same fashion as position.