Jump to content
Sign in to follow this  
Extrude Ragu

Relative Movement in terms of Orientation

Recommended Posts

Hi There.

 

  I am working with a kinda lousy sliding door script I want to improve. See, the door when opens, it moves in a set direction.


  What I want to do is change this so that the door moves relative to it's current orientation, without having to change the script every time I reorientate the door to face another way.

 

The current script if you want to see. The door is controlled by an external command on channel 6789 that says 'door';

 

 

float       NorthSouth =1.0;
//Positive = move east, negative = move west
float       EastWest =0.0;
//Positive = move up, negative = move down
float       UpDown = 0.0;

//The amount in seconds to stay open, set to 0 to not autoclose
float       Timer = 15.0;

//Sound to play on open, either a UUID or a name in the door contents
//if a name, it must be exact. Leave at "" for no sound
string      OpenSound = "50dceba2-cb07-6577-1fd7-ca288abdf921";

//Volume to play open sound, 0.0 is same as no sound, 1.0 is max
float       OpenVol = 1.0;

//Sound to play on close, either a UUID or a name in the door contents
//if a name, it must be exact. Leave at "" for no sound
string      CloseSound = "50dceba2-cb07-6577-1fd7-ca288abdf921";

//Volume to play close sound, 0.0 is same as no sound, 1.0 is max
float       CloseVol = 1.0;


//misc variables
vector      Pos;
vector      Offset;
integer     Open;
integer     x;

default
{
    state_entry()
    {
        Offset = <EastWest, NorthSouth, UpDown>;
        llListen(6789, "", NULL_KEY, "" );
     }
    on_rez(integer num)
    {
    }
    listen(integer number, string name, key id, string message)
    {
       if (message == "Door")
    {
                Pos = llGetLocalPos();
                if(OpenSound != "") llTriggerSound(OpenSound, OpenVol);
                llSetPos(Pos + Offset);
                state open;
    }
}
}

state open
{
    state_entry()
    {
        llListen(6789, "", NULL_KEY, "" );
         }
          on_rez(integer num)
         {
         }
          listen(integer number, string name, key id, string message)
          {
          if (message == "Door")
          {
        
         if(CloseSound != "") llTriggerSound(CloseSound, CloseVol);
         llSetPos(Pos);
         state default;
     }
    }
         
}

Share this post


Link to post
Share on other sites

Hi There.

 

  I am working with a kinda lousy sliding door script I want to improve. See, the door when opens, it moves in a set direction.


  What I want to do is change this so that the door moves relative to it's current orientation, without having to change the script every time I reorientate the door to face another way.

 

The current script if you want to see. The door is controlled by an external command on channel 6789 that says 'door';

 

 

float       NorthSouth =1.0;
//Positive = move east, negative = move west
float       EastWest =0.0;
//Positive = move up, negative = move down
float       UpDown = 0.0;

//The amount in seconds to stay open, set to 0 to not autoclose
float       Timer = 15.0;

//Sound to play on open, either a UUID or a name in the door contents
//if a name, it must be exact. Leave at "" for no sound
string      OpenSound = "50dceba2-cb07-6577-1fd7-ca288abdf921";

//Volume to play open sound, 0.0 is same as no sound, 1.0 is max
float       OpenVol = 1.0;

//Sound to play on close, either a UUID or a name in the door contents
//if a name, it must be exact. Leave at "" for no sound
string      CloseSound = "50dceba2-cb07-6577-1fd7-ca288abdf921";

//Volume to play close sound, 0.0 is same as no sound, 1.0 is max
float       CloseVol = 1.0;


//misc variables
vector      Pos;
vector      Offset;
integer     Open;
integer     x;

default
{
    state_entry()
    {
        Offset = <EastWest, NorthSouth, UpDown>;
        llListen(6789, "", NULL_KEY, "" );
     }
    on_rez(integer num)
    {
    }
    listen(integer number, string name, key id, string message)
    {
       if (message == "Door")
    {
                Pos = llGetLocalPos();
                if(OpenSound != "") llTriggerSound(OpenSound, OpenVol);
                llSetPos(Pos + Offset);
                state open;
    }
}
}

state open
{
    state_entry()
    {
        llListen(6789, "", NULL_KEY, "" );
         }
          on_rez(integer num)
         {
         }
          listen(integer number, string name, key id, string message)
          {
          if (message == "Door")
          {
        
         if(CloseSound != "") llTriggerSound(CloseSound, CloseVol);
         llSetPos(Pos);
         state default;
     }
    }
         
}

Share this post


Link to post
Share on other sites

All you need to do in each of your llSetPos statements is remember to multiply the position by the door's local rotation (which, in the case of a one-prim door, is its global rotation).  Take a look at http://community.secondlife.com/t5/LSL-Library/Linkable-Multiprim-Sliding-Door/m-p/722649#M36 , which deals with the slightly more complicated case of a multiprim sliding door.

Share this post


Link to post
Share on other sites

As Dora says, rotations are often easier to implement than to grasp.    For what it's worth, I find it helpful to think of "multiplying" by llGetRot() as the equivalent of telling the script to use the Local ruler mode when moving the prim.

One of the big gotcha's (which is why I put scare quotes round "multiplying") is that you're not really multiplying the rotation.   You're "translating" it.   The practical effect of this is the order in which you write the instructions matters.    Rotation rot * llGetRot() is not the same as llGetRot()* rot.

There's two very helpful tutorials on rotations over at SLU by Grandma Bates:  Basic Introduction to Rotations and Introduction to Rotations with Translations.

Share this post


Link to post
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.

Sign in to follow this  

×
×
  • Create New...