move an object to dynamic place with expression


#1

hey guys
I want to move pSphere1 to pSphere2 , but the position of pSphere2 can change in every frame , something like track an object til get it . the position in 3D axis is different ( positive and negative ) . How can i track this object ?
I used this code :

float $Target_pos[] = xform -q -ws -t "pSphere2";

float $pSphere1_pos[] = xform -q -ws -t "pSphere1";

setAttr “pSphere1.translateX” ($pSphere1_pos[0] - 1);
setAttr “pSphere1.translateZ” ($pSphere1_pos[2] + 1);

in this case pSphere2 pass my target :curious: i want to stay when arrived