Jump to content

Rotations are still giving me the creeps...


Guest
 Share

Recommended Posts

Hi everyone, I want to use the following build for an upcoming game: a safe that opens if the player gives the correct input to a "simon game". I have bought a full perm safe including a script which is in the door child prim.

 

integer opened = FALSE;

default
{
    touch_start(integer total_number)
    {
            if (opened == TRUE)
            {
            llTriggerSound("XXXXXX-1c68-79dd-8692-cd8f450a7213",1);
            llSetLinkPrimitiveParams(llGetLinkNumber(),[
            PRIM_POS_LOCAL,llGetLocalPos() - <0.415,0,0.415>,
            PRIM_ROT_LOCAL,llGetLocalRot() / <0,1,0,1>]);
            opened = FALSE;
            }
            else if (opened == FALSE)
            {
            llTriggerSound("XXXXXXX-4fbf-a0a5-c975-01664fed13ea",1);
            llSetLinkPrimitiveParams(llGetLinkNumber(),[
            PRIM_POS_LOCAL,llGetLocalPos() + <0.415,0,0.415>,
            PRIM_ROT_LOCAL,llGetLocalRot() * <0,1,0,1>]);
            opened = TRUE;
        }
    }
}

 

Then I have bought a full perm simon game and I have linked it to the safe (both door and simon game are now child prims, the script is in the door child prim). I have altered the safe door script like this:

 

vector relativePosOffset = <-0.4657, 0.3693, 0.0>; // 
vector relativePosOffset2 = <0.4657, -0.3693, 0.0>; // 



integer simonLink;
integer opened = FALSE;

default
{
 state_entry()
   {
    //Start variables for Linked Prims////////////
    integer p;

for (p=1;p<=llGetNumberOfPrims();p++)
{
    if (llGetLinkName(p) == "Simon")
    {
    llOwnerSay("Found Simon");
    simonLink = p;
    }
}
    }

    //llOwnerSay("Debugging: " + (string)Gwwg);
//End variables for linked prims//////////////

    touch_start(integer total_number)
    {
            if (opened == TRUE)
            {
            llTriggerSound("XXXXXXXX-1c68-79dd-8692-cd8f450a7213",1);
            llSetLinkPrimitiveParams(llGetLinkNumber(),[
            PRIM_POS_LOCAL,llGetLocalPos() - <0.415,0,0.415>,
            PRIM_ROT_LOCAL,llGetLocalRot() / <0,1,0,1>]);
            opened = FALSE;

            llSetLinkPrimitiveParams(simonLink,[PRIM_POS_LOCAL,relativePosOffset,PRIM_ROT_LOCAL,llEuler2Rot(<0.0, 0.0, 90.0> * DEG_TO_RAD)]);

            }
            else if (opened == FALSE)
            {
            llTriggerSound("XXXXXXXX-4fbf-a0a5-c975-01664fed13ea",1);
            llSetLinkPrimitiveParams(llGetLinkNumber(),[
            PRIM_POS_LOCAL,llGetLocalPos() + <0.415,0,0.415>,
            PRIM_ROT_LOCAL,llGetLocalRot() * <0,1,0,1>]);
            opened = TRUE;

            llSetLinkPrimitiveParams(simonLink,[PRIM_POS_LOCAL,relativePosOffset2, PRIM_ROT_LOCAL,llEuler2Rot(<.0, .0, 270.0> * DEG_TO_RAD)]);

        }
    }
}

 

In default position (the safe door is closed, I find the following rotation values in the "object" pannel of the "build" floater:

- root prim: X:90, Y: 0, Z:0

- door child prim: X:90, Y: 0, Z:0

- Simon game child prim: X:0, Y:0, Z: 180 

The expected behaviour would have been that the "simon game" prim is rotated 90 degrees counter-clockwise on the z-axis, when I click on the door and open it. BUT additionally to that it also gets rotated by 90 degrees on the X-axis (why is that?). After opening the door I have the following values:

- root prim: X:90, Y: 0, Z:0

- door child prim: X:0, Y: 90, Z:90

- Simon game child prim: X:90, Y:0, Z: 270 

And after closing the door by clicking the door prim again, it doesn't rotate back to the default rotation, but by only 180 degrees on the Z-axis, that's now really confusing me:

- root prim: X:90, Y: 0, Z:0

- door child prim: X:90, Y: 0, Z:0

- Simon game child prim: X:90, Y:0, Z: 90

HELP?

 

Link to comment
Share on other sites

The edit tab shows you the GLOBAL rotation relative to the sim.

The script uses LOCAL rotations relative to the root.

So on 1st click the Simon prim will align with the root and on the next clicks it will shift between 2 positions. You don't rotate back and forth you rotate 90° on the local Z-axis then 270° into the same direction then 90° and so on. So you don't do 180° rotations as you expected. After 2 moves you did a full 360° rotation so it isn't that obvious maybe.
Looks to me that you want to use 180° and -180° or 180° and 180°.

 

Link to comment
Share on other sites

Thanks a lot for your reply. I was able to solve it with trial and error. Things get a bit nasty when the root doesn't have zero rotation and also the child prim has already rotated axis. I had to - amongst other stuff - to compensate for the root prim rotation of the X-axis with a -90 degrees rotation of the child at the first instance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...