Maitimo Posted September 12, 2022 Share Posted September 12, 2022 I have a sliding door script below. The problem I have with it, is that it moves from fully closed to fully open in an instant. How do I get it to slide slowly, in increments of, say, 0.2m per sec? What lines do I need to add and where do I put them? //Sliding Door v4 //Works when linked //by Kayla Stonecutter //How far in meters to travel in each direction. Two or all three can be used for angled movement //NOTE: when linked, this is relative to the root prim //Positive = move north, negative = move south float NorthSouth = 0.0; //Positive = move east, negative = move west float EastWest = 1.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 = "cb340647-9680-dd5e-49c0-86edfa01b3ac"; //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 = "e7ff1054-003d-d134-66be-207573f2b535"; //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>; } touch_start(integer num) { for(x = 0; x < num; x++) { Open = !Open; if(Open) { Pos = llGetLocalPos(); if(OpenSound != "") llTriggerSound(OpenSound, OpenVol); llSetPos(Pos + Offset); llSetTimerEvent(Timer); }else{ if(CloseSound != "") llTriggerSound(CloseSound, CloseVol); llSetPos(Pos); llSetTimerEvent(0); } } } on_rez(integer param) { llResetScript(); } moving_end() { if(Open) { Open = 0; llSetTimerEvent(0.0); } } timer() { if(CloseSound != "") llTriggerSound(CloseSound, CloseVol); llSetPos(Pos); llSetTimerEvent(0); Open = 0; } } Link to comment Share on other sites More sharing options...
Quistess Alpha Posted September 12, 2022 Share Posted September 12, 2022 (edited) Unfortunately, for a linked sliding door you can't get truly smooth movement. but you can move a thing in small increments until it's where you want it to be. // linked sliding door script. // Quistess Alpha 2022. vector gDelta = <1.0, 0, 0>; // x,y,z distance to move with respect to the prim // (edit linked, snap-local and check the directions of the red(x) green(y) and blue(z) arrows) integer gSteps = 28; // how many steps does it take to get from closed to open? float gTimeMove = 7.0; // how many seconds does it take to get from closed to open? float gTimeStayOpen = 15.0; // how long to stay open, 0 for indefinitely. string OpenSound = "cb340647-9680-dd5e-49c0-86edfa01b3ac"; string CloseSound = "cb340647-9680-dd5e-49c0-86edfa01b3ac"; // script managed variables: integer isOpen = FALSE; open_door(integer open) // let open = 1 to open, 0 to close. { if(isOpen!=open) { isOpen=open; }else { llOwnerSay("Warning: attemting to set door state to current state."); return; //do not open the door if it is already open, do not close if already closed. } if(open) { if(OpenSound) llPlaySound(OpenSound,1.0); llSetTimerEvent(gTimeStayOpen); }else { if(CloseSound) llPlaySound(CloseSound,1.0); llSetTimerEvent(0.0); } open = (2*open) -1; // if open is 0, set it to -1. vector pos = llGetLocalPos(); rotation rot = llGetLocalRot(); vector delta = (gDelta*rot)*open; integer loop=1; for(;loop<=gSteps;++loop) { llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_POS_LOCAL,pos+(delta*loop)]); llSleep(gTimeMove); //llOwnerSay("tick"); } } default { state_entry() { // convert global variables to more useful formats. gDelta = gDelta/gSteps; if(gTimeStayOpen) gTimeStayOpen+=gTimeMove; gTimeMove = gTimeMove/gSteps; } touch_start(integer total_number) { open_door(!isOpen); } timer() { open_door(0); // close door. (also sets timer to 0). } } Or so should work as a basic example, making a version that lets you shut it mid-opening or open mid-closing would be a tad more complicated. Edited September 13, 2022 by Quistess Alpha correctly handle the case when gTImeStayOpen is set to 0. 1 Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted September 12, 2022 Share Posted September 12, 2022 (edited) 2 hours ago, Maitimo said: if(Open) { Pos = llGetLocalPos(); if(OpenSound != "") llTriggerSound(OpenSound, OpenVol); llSetPos(Pos + Offset); llSetTimerEvent(Timer); }else{ if(CloseSound != "") llTriggerSound(CloseSound, CloseVol); llSetPos(Pos); llSetTimerEvent(0); } See this part? llSetPos is what the script uses to open/close the door. Instead of just calling llSetPos once with the final destination, you would need a loop that uses llSetPos multiple times with only a short distance. (Calculating the offset or time-to-open is the trickiest part.) Also, llSetPos causes the script to wait 0.2 seconds before doing anything else, so you would end up with a very slow door. You can use llSetRegionPos instead, which works exactly the same but without waiting all the time. Edited September 12, 2022 by Wulfie Reanimator 1 Link to comment Share on other sites More sharing options...
Love Zhaoying Posted September 13, 2022 Share Posted September 13, 2022 I did it by adding a "# steps" factor, then dividing each of the "total x movement" and "total y movement" by "# steps" to get the "incremental" x and y movement for each timer event. When the final X or Y position is within 0.01 (or whatever you choose) for that direction, you stop moving in that direction. When both are within the 0.001 (or whatever you choose), you stop the timer. Storing both the start, end, and even a "third" X/Y position, this worked pretty well for going in either direction. Sorry, mostly Foruming from phone and would have to login and search for my script. Link to comment Share on other sites More sharing options...
Maitimo Posted September 13, 2022 Author Share Posted September 13, 2022 16 hours ago, Quistess Alpha said: Unfortunately, for a linked sliding door you can't get truly smooth movement. but you can move a thing in small increments until it's where you want it to be. Or so should work as a basic example, making a version that lets you shut it mid-opening or open mid-closing would be a tad more complicated. This works perfectly, thank you Quistess. Sorry to the rest of you, I don't understand anything of what you said or how to turn that information into a script. But this one is exactly what I needed. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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