I researched and tested many hours without success. What I've done so far is to rotate a PRIM in the direction to an avatar,
so that the PRIM looks at the target avatar.
2 Solutions
a)
// get the traget position
vector targetPos = llList2Vector( llGetObjectDetails( KEY, [OBJECT_POS]), 0);
llLookAt(targetPos,1,1);
b)
vector startPos = llGetPos();
float distance=llVecDist(<targetPos.x,targetPos.y,0>,<startPos.x,startPos.y,0>);
rotation rot = llRotBetween(<1,0,0>,llVecNorm(<distance,0,targetPos.z - startPos.z>)) * llRotBetween(<1,0,0>,llVecNorm(<targetPos.x - startPos.x,targetPos.y - startPos.y,0>));
llSetRot(rot);
Both methods work great if the PRIM is on the ground and not attached to an avatar.
Now the tricky part, I need the same behavior when the PRIM is attached on my avatar (eg. on pelvis or center point, ...).
I know the above methods are not suitable for this case. I've tried a lot to adapt method b) for my needs using llGetLocalPos(),
llGetLocalRot(), llSetLocalRot() in combination with llGetPos() and llGetRot() but without success. My PRIM looks always in the wrong direction.
Meanwhile Im lost in this rotation jungle. Would be great if someone can help.