How do I translate the positions of particles in a Particles array to world coordinates? The only function I can find to do such a translation is TransformPoint, but it requires a transform. With a Particles array, all I have is positions. Is there any way to use this function with particle positions, or another way to get their world coordinates? I could write my own function to do this, but I’m afraid it would be slow with lots of particles.
Converting from local to world coordinates is not as simple as I thought. I can’t just add the local coordinates of the particles to the world coordinate of their parent. I see I need to take the parent’s rotation into account, and that’s got me stuck, what with my limited math skills. Any suggestions on how to do this?
If you enable the Simulate In World Space option, the particles’ positions will automatically be in world space. If you need to keep them in local space, then the transform you need is the one belonging to the emitter object:-
var localPos = emitterObj.particleEmitter.particles[0].position;
var worldPos = emitterObj.TransformPoint(localPos);
Thanks. That works. But InverseTransformPoint does not. When I convert the local positions to world and then back, they are positioned as if the parent is at 0,0,0 with a rotation of 0.
Maybe if I explained what I was trying to do, it might make more sense. I have a cluster of particles surrounding a parent object. They need to move with the object, so they cannot be in world space. When the parent object gets close to another object, it moves toward the second object. I need to deform the particles during this movement so they look like they are stretching toward that second object, with the closer particles moving more than the more distant ones.
So I convert the particles to world coordinates (TransformPoint), adjust their positions toward that second object with the closer ones moving more, then convert back to local coordinates (InverseTransformPoint), and update the particle array. This works as long as the parent object is a 0,0,0 with a rotation of 0. If the parent is anywhere else, the particles jump back to that position when updated. Doesn’t matter where the parent is or where it started out. It’s like I’m missing a step, or some additional translation.
Turns out, it was exactly like that.