Position of Child Objects within an Animation

Hi, I have an animation that has 3 child objects. I can get the Z positions of these child objects with this code. Each child object has a rigid body and box collider.:

function OnMouseDown () {
var Zposition = transform.localPosition.z ;
print (Zposition);
}

This works fine.

However, when I play the animation, the Child objects move forward along the Z axis and I can’t retrieve their new Z position. I keep getting the same old Zpositions.

Is it possible to get the updated Z positions of Child objects after they have animated to their new positions.

Any insight would be greatly appreciated.

Thanks.

you’re calling it on mouse down which is a singular event. maybe?

function Update()
{
print (transform.localposition.z);
}

Thanks for the reply Pete. My animation is a tool with a bunch of smaller pieces.

When the animation plays, it expands the tool, and all the pieces move to new locations. What I’d like to do is click on each piece (the Child objects) and get their new locations once they have animated. Particularly their forward Z position.

This works with the function OnMouseDown(), my only problem is that it keeps returning the old Z position. No matter where the Child objects have moved to.

just a thought, are they moved in unity or in your animation app? if it’s in your app, their origin stays the same. so they’re in the same position just offset from their origin.

Yes, the animation is created in Lightwave.

I guess there is no way to detect the offset location of those Child objets once the tool has expanded?

Thanks Pete.

unfortunately their pivot point is still at 0,0,0 (or wherever it is in lightwave). that’s their transform in unity. so the objects themselves don’t actually move. sorry!