Jump to content
trivis

rotation childprim to point to avatar

Recommended Posts

At first it seemed not too difficult to tackle the following problem, but in the end I did not manage to do it. Rotations are the story of my (second) life :-)

The problem: I have an object consisting of several prims. When someone touches the object i would like to point one of the childprims to the avatar who touched the object. See attached picture.

The rotation of (only!) that childprim only need to be done around in its XY-plane, so only a rotation around its Z-axis.

Does anyone has a working solution?

Thanks in advance for any help.

 

rotation question.png

Share this post


Link to post
Share on other sites

mebbe something kinda like this? ( change child = 2  to whatever link you are rotating...)

 

integer child = 2;
vector  vPosTarget;  
vector pos ;
default
{
    state_entry()
    {
    }
    on_rez(integer param)
    { 
    }
    touch_start(integer num)
    {   pos = llGetPos();  
        vPosTarget = llDetectedPos(0); 
        llSetLinkPrimitiveParamsFast( child,
        [  PRIM_ROT_LOCAL ,  llRotBetween( <1.0, 0.0, 0.0>, llVecNorm( <vPosTarget.x, vPosTarget.y, pos.z> - pos ) )  ]);
    }   
}

 

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

Wonderful!

Thank you Xiija!! This does the job!

Still discovering how you did this :-) but many thanks.

Kind regards,
trivis

Edited by trivis
  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)
On 5/28/2018 at 9:05 AM, trivis said:

Still discovering how you did this :-)

I think I can kind of explain that in a semi-concise way.

  • "llRotBetween returns a rotation that is the shortest rotation between the direction start and the direction end."
     
  • "<1, 0, 0>" is just a forward vector. The "front face" in this context.
     
  • "<vPosTarget.x, vPosTarget.y, pos.z>" is the target's position except on the same level as the child prim. (Child's height position.)
    This is important because you don't want the child prim to point up or down, only horizontally.
     
  • "<vPosTarget.x, vPosTarget.y, pos.z> - pos" makes sure the position is relative to the targeting object.
    This is important because otherwise it would probably point in the wrong direction.
     
  • llVecNorm just "normalizes" the relative offset so that the vector has "a total length of 1.0."
    Personally I haven't found this to ever be necessary but I guess it might prevent some math errors.
     
  • Then you just apply the rotation given by llRotBetween, which will point the child's front face towards the relative direction of the target avatar.
Edited by Wulfie Reanimator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×