Jump to content

Relative Movement in terms of Orientation


Extrude Ragu
 Share

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

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

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;
     }
    }
         
}

Link to comment
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;
     }
    }
         
}

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

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

Link to comment
Share on other sites

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

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

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
 Share

×
×
  • Create New...