Jump to content

Rotation not rotating the way I want it to


EQINOX Corbin
 Share

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

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

Recommended Posts

What I am trying to do is build a mesh aircraft with a mesh turret on top that can rotate from facing forward 180 to face back now  the script I have  works perfectly  when I link the mesh turret to a standard prim and then put the script in the now root standard prim and then ware it and this works  however I am now trying to make it part of the vehicle so people  don't have to ware this part.  However when I link the mesh turret  with the mesh build and place the rotation script in the turret it nolonger rotates correctly instead or rotating horizontally it rotates vertically.

 

Here is a very basic pic of what is happening  and what I want.

#1 is what is happening when I link the  2 parts in the image  its as if your looking at the front of the build

#2 this is how I need it to move when  both parts are linked  in this pic  you are looking  down on the build with the black dot being  the front of the build.

Untitled.jpgThe scrip

The script i am useing is the following;

// The default values are specified below. 
// Please note that these get overridden by reading from the 
// notecard, "Door Values."
float angle = 90.0;
integer numAngles = 20;
float timeOpen = 15.0;
integer closeAutomatically;

// Variables necessary for door operation.
rotation baseRot;
vector basePos;
vector scale;


// Keys for reading notecards
key readAngle;
key readNumAngle;
key readTime;
key readShut;

// variables indicating the door states
integer open;
integer changingDoor;

// Variables for listening for the close command
integer channel;
integer listenControl;

toggleDoor() {
    integer doorSwing;
    rotation rotThrough;
    rotation theBase;

    if(changingDoor) {
        llSay(0,"The door is currently in operation. Please try again shortly.");
        return;
    }

    //llSay(0,(string)llGetLinkNumber());
    if( (llGetLinkNumber() != LINK_ROOT) && ( llGetLinkNumber() != 0) ) {
        theBase = llGetRootRotation();
    } else {
        theBase = ZERO_ROTATION;
    }
    changingDoor = TRUE;
    if (open) {
        // close the door.
        open = FALSE;
        for (doorSwing=numAngles;doorSwing>=0;--doorSwing) {
            rotThrough = llEuler2Rot(
               <angle*PI/180.0*((float)doorSwing)/((float)numAngles),0.0,0.0>);
            llSetPrimitiveParams([PRIM_ROTATION,rotThrough*baseRot/theBase,
                PRIM_POSITION,basePos + <.2*scale.x,0.0,0.0>*rotThrough*baseRot -
                    <.2*scale.x,0.0,0.0>*baseRot]);
            //llSetLocalRot(rotThrough*baseRot);
            //llSetPos(basePos + <0.5*scale.x,0.0,0.0>*rotThrough*baseRot
            //                      - <0.5*scale.x,0.0,0.0>);
        }
        llSetLocalRot(baseRot);
        llSetPos(basePos);
    } else {
        // open the door.
        open = TRUE;
        for (doorSwing=0;doorSwing<=numAngles;++doorSwing) {
            rotThrough = llEuler2Rot(
               <angle*PI/180.0*((float)doorSwing)/((float)numAngles),0.0,0.0>);
            llSetPrimitiveParams([PRIM_ROTATION,rotThrough*baseRot/theBase,
                PRIM_POSITION,basePos + <.2*scale.x,0.0,0.0>*rotThrough*baseRot -
                    <.2*scale.x,0.0,0.0>*baseRot]);
            //llSetLocalRot(rotThrough*baseRot);
            //llSetPos(basePos + <0.5*scale.x,0.0,0.0>*rotThrough*baseRot
            //                      - <0.5*scale.x,0.0,0.0>);
        }
    }
    changingDoor = FALSE;

}




default
{
    state_entry(){

llListen(  700, "", NULL_KEY, "" ); 
        // Request to read the values from the notecard.
        readAngle    = llGetNotecardLine("Door Values",1);
        readNumAngle = llGetNotecardLine("Door Values",3);
        readTime     = llGetNotecardLine("Door Values",5);
        readShut     = llGetNotecardLine("Door Values",7);

        baseRot = llGetLocalRot();
        basePos = llGetLocalPos();
        scale = llGetScale();
        open = FALSE;
        changingDoor = FALSE;
        closeAutomatically = TRUE;
        
      
       
       
        

    }

    // Make sure I reset myself when rezzed
    on_rez(integer param) {
        llResetScript();
    }

  
listen( integer channel, string name, key id, string message )
{
    
       if ( message == "on" )
    { 
       
 
         
   
         if(!open && (!changingDoor) ) {
            baseRot = llGetLocalRot();
            basePos = llGetLocalPos();
            scale = llGetScale();
            toggleDoor();
            // wait to close the door
            if(closeAutomatically) {
                llSetTimerEvent(timeOpen);
            }
        } else if ( !closeAutomatically && open && (!changingDoor)  ) {
            toggleDoor();
        } else {
            llSay(0,"Sorry I am already open. Please wait until I close");
        }

    
    }
else if ( message == "off" )
        {
   
         if(!open && (!changingDoor) ) {
            baseRot = llGetLocalRot();
            basePos = llGetLocalPos();
            scale = llGetScale();
            toggleDoor();
            // wait to close the door
            if(closeAutomatically) {
                llSetTimerEvent(timeOpen);
            }
        } else if ( !closeAutomatically && open && (!changingDoor)  ) {
            toggleDoor();
        } else {
            llSay(0,"Sorry I am already open. Please wait until I close");
        }

}



}

      


    timer() {
        // close the door as long as I am not in operation
        if(open && (!changingDoor) ) {
            toggleDoor();
            llSetTimerEvent(0.0);
        }
    }

        
    // Routine to read the values from the notecard.
    dataserver(key query_id, string data) {
        if (readAngle == query_id) {
            // read in the angle to open to
            angle = (float) data;
           // llOwnerSay("The angle that the door will turn is " +
                      // (string) angle);
            readAngle = NULL_KEY;
        } else if (readNumAngle == query_id) {
            // read in the number of steps to take
            numAngles = (integer) data;
           // llOwnerSay("The number of increments it turns is " + (string)numAngles);
            readNumAngle = NULL_KEY;
        } else if (readTime == query_id) {
            // read in how long the door will be open
            timeOpen = (float) data;
           // llOwnerSay("The time that the door is open is " + (string)timeOpen);
            readTime = NULL_KEY;
        } else if (readShut == query_id) {
            closeAutomatically = (llToUpper(data) == "YES");
            if(closeAutomatically) {
               // llOwnerSay("I will shut automatically");
            } else {
               // llOwnerSay("I will not shut automatically.");
            }
            readShut = NULL_KEY;
        }
            
            
    }

    // If the inventory has changed re-read the door parameters
    changed(integer change) { 
        if(change & CHANGED_INVENTORY) {
            // Request to read the values from the notecard.
            readAngle    = llGetNotecardLine("Door Values",1);
            readNumAngle = llGetNotecardLine("Door Values",3);
            readTime     = llGetNotecardLine("Door Values",5);
            readShut     = llGetNotecardLine("Door Values",7);
        }
    }
        
    
}
    

 

any help to get theis rotateing  corectly would be great as it starting to frustraite me >.<

Link to comment
Share on other sites

Well, since it is getting baseRot from that prim's local rotation, just add an extra rotation to it.  You want to rotate the local X axis vertical, so (....doing this in my head .... ) this ought to work......

baseRot = llEuler2Rot(<0.0,PI/2,0.0>*llGetLocalRot();

Thing is, you are using an overkill door script for a job that really doesn't need all of its baggage.  It would be much better to write yourself a short script that handles the movement instead of modifying this monster.  It's easy to get lost in this thicket of code.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4474 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...