Jump to content

How to change Link Child llSitTarget() to look at the Root Prim ?


chrixbed
 Share

You are about to reply to a thread that has been inactive for 1421 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm building an object with 6 pose ball that I want to look at the root. I can change the orientation of each pose ball but if I try to apply the calculated orientation to the pose ball the llSitTarget() seem not to follow that. What I'm doing wrong ?

Here is the code I put in every Link Child Prim:

rotation LinkedLookAt( vector Target){
    rotation rotvec = llRotBetween(<0,1,0>,llVecNorm((Target - llGetPos())));
    rotation rotbet = rotvec/llGetRootRotation();
    llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, rotbet]);
    return rotbet;
}
default
{
    state_entry()
    {
        // Get the Root Prim orientation
        list ListPosLocal = llGetLinkPrimitiveParams(1, [PRIM_POS_LOCAL]);
        // Tag the prim to identify it
        llSetLinkPrimitiveParamsFast( LINK_ROOT, [PRIM_TEXT, (string)["(Root)",llList2String(ListPosLocal,1)], <1,1,1>, 1]);
        // Change Prim Orientation to look at the Root
        vector posroot = llList2Vector(ListPosLocal,0);
        rotation LookRoot = LinkedLookAt(posroot);
        // Apply this orientation on the Sit Target
        llSitTarget(<0.0, 0.0, 0.4>, LookRoot);
    }
   
}

 

Link to comment
Share on other sites

You have been rotating the prim to make its +Y axis point at the root, so you need to turn the sit rotation by 90 degrees from its default, which is relative to the child prim's  local +X direction.  Then, to make the sit rotation a true local rotation, you need to correct not for the root's rotation but for the rotation of the entire linkset.  So

    return llEuler2Rot(<0.0,0.0,PI/2>)*rotvec/llGetRot();

EDIT:  In case that's not clear,  the rotation that you put in llSitTarget is normally intended to be a local rotation relative to the prim you are sitting on.  In this case, though, you want to set the rotation relative to the linkset's own rotation, as if you are attaching a new prim (the avatar) to the linkset, not to the child prim.  That's why you need to first correct rotvec by removing the rotation of the  linkset (to make it a local rotation relative to the linkset) and then correct that by multiplying by llEuler2Rot(<0.0,0.0,PI/2>) to make the sit target aim at the prim's +Y axis instead of its +X axis.

Edited by Rolig Loon
Cleaner wording
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

57 minutes ago, Sabrina Tamerlane said:

llSitTarget(<0.0, 0.0, 0.4>, ZERO_ROTATION/llGetLocalRot());

I try to apply this on all the prim that Avatar will sit on by modifying only llSitTarget() and not call the rotation for the prim it self. But his case is not working.

rotation LinkedLookAt( vector Target){
    rotation rotvec = llRotBetween(<0,1,0>,llVecNorm((Target - llGetPos())));
    rotation rotbet = rotvec/llGetRootRotation();
    llSetRot(rotbet);
//    return rotbet;
    return llEuler2Rot(<0.0,0.0,-PI/2>)*rotvec/llGetRot();
}
default
{
    state_entry()
    {
        list ListPosLocal = llGetLinkPrimitiveParams(1, [PRIM_POS_LOCAL]);
        llSetLinkPrimitiveParamsFast(1, [PRIM_TEXT, (string)["(Root)",llList2String(ListPosLocal,1)], <1,1,1>, 1]);
        llOwnerSay("Root Pos 2: " + llList2String(ListPosLocal,0));
        vector posroot = llList2Vector(ListPosLocal,0);
        LinkedLookAt(posroot);
       // llSitTarget(<0.0, 0.0, 0.4>, LinkedLookAt(posroot)); // Too complex
        llSitTarget(<0.0, 0.0, 0.4>, ZERO_ROTATION/llGetLocalRot()); // More Simple way
    }
}

 

Link to comment
Share on other sites

1 hour ago, Rolig Loon said:

You and everybody else.   ;)  The biggest challenge is always to figure out which reference frame to use.  If it were easy, everyone would be a scripter.

Which rot to put first? Divide or multiply? Local or global? Ahh, whatever. Try all the permutations until it works!

  • Haha 4
Link to comment
Share on other sites

1 minute ago, chrixbed said:

I try to apply this on all the prim that Avatar will sit on by modifying only llSitTarget() and not call the rotation for the prim it self. But his case is not working.

 

You can verify with this:

 

 llSetLocalRot(ZERO_ROTATION) ;
 llSitTarget(<0.0, 0.0, 0.4>, ZERO_ROTATION);

If the avatar is not facing the root prim then you need to make some corrections, in my case I ended up with this, which is quite similar to Rollig's code:

 

llSitTarget(<0.0, 0.0, 0.4>, llEuler2Rot(<0.0,0.0,PI/2>)*ZERO_ROTATION/llGetLocalRot());

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1421 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...