Jump to content

Rotating Door Help. *Solved*


Tomkinson
 Share

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

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

Recommended Posts

I have a script for an automatic rotating door that I am using on my island. When something says "open" on channel 200 it opens. I've implimented this buy having some invisible pads on either side of the door that say "open" when you walk over them. However, when the door is already open and you stumble accross a pad it closes the door. This is fine for just one person going through the door but I am expecting a lot of traffic through the door once the island is live. I can't for the life of me work out how to stop the door from closing when it hears the the command, I'd like it to reset it's timer so that the next people could walk through without the door trapping them inside. Can anyone help?

Here is the code...

// Smooth Door Script - Version 1.2
// by Toy Wylie
// Distributed under the following licence:
// - You can use it in your own works
// - You can sell it with your work
// - This script must remain full permissions
// - This header notice must remain intact
// - You may modify this script as needed

float openingTime=0.5; // in seconds
float openingAngle=90.0; // in degrees
float autocloseTime=5.0; // in seconds
integer steps=4; // number of internal rotation steps
integer world=TRUE; // align to world or root prim rotation

string soundOpen="door_open";
string soundClose="door_close";

float omega=0.0;

vector axis;
rotation closedRot;
rotation openRot;

integer swinging;
integer open;

sound(string name)
{
if(llGetInventoryType(name)==INVENTORY_SOUND)
llTriggerSound(name,1.0);
}

openDoor(integer yes)
{
if(yes)
sound(soundOpen);

vector useAxis=axis;
open=yes;

if(!yes)
useAxis=-axis;

llSetTimerEvent(openingTime/(float) steps);
llTargetOmega(useAxis,omega,1.0);
}

go()
{
if(swinging==0)
{
if(!open)
{
axis=<0.0,0.0,1.0>/llGetRootRotation();

closedRot=llGetLocalRot();

if(world)
openRot=llGetRot()*llEuler2Rot(<0.0,0.0,openingAngle>*DEG_TO_RAD)/llGetRootRotation();
else
openRot=closedRot*llEuler2Rot(<0.0,0.0,openingAngle>*DEG_TO_RAD);
}
swinging=steps;
openDoor(!open);
}
}

rotation slerp(rotation source,rotation target,float amount)
{
return llAxisAngle2Rot(llRot2Axis(target/=source),amount*llRot2Angle(target))*source;
}

default
{
state_entry()
{
swinging=0;
open=FALSE;
omega=TWO_PI/360*openingAngle/openingTime;
llTargetOmega(ZERO_VECTOR,1.0,1.0);
llListen(200,"","","");
}

touch_start(integer dummy)
{
go();
}

collision_start(integer dummy)
{
go();
}
listen(integer channel, string name, key id, string message)
{
if(message =="open")
{
go();
}
else
{
}
}

timer()
{
if(swinging>0)
{
swinging--;
if(swinging!=0)
{
float amount=(float) swinging/(float) steps;
if(open)
amount=1.0-amount;
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,slerp(closedRot,openRot,amount)]);
return;
}

llTargetOmega(axis,0.0,0.0);
if(open)
{
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,openRot]);
llSetTimerEvent(autocloseTime);
}
else
{
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,closedRot]);
sound(soundClose);
llSetTimerEvent(0.0);
}
}
else // autoclose time reached
{
llSetTimerEvent(0.0);
openDoor(!open);
swinging=steps;
}
}
}

 Thanks in advance. 

Link to comment
Share on other sites

First of all it would be very very nice if you could post the script so that humans can read it:)

// Smooth Door Script - Version 1.2// by Toy Wylie// Distributed under the following licence:// - You can use it in your own works// - You can sell it with your work// - This script must remain full permissions// - This header notice must remain intact// - You may modify this script as neededfloat openingTime=0.5; // in secondsfloat openingAngle=90.0; // in degreesfloat autocloseTime=5.0; // in secondsinteger steps=4; // number of internal rotation stepsinteger world=TRUE; // align to world or root prim rotationstring soundOpen="door_open";string soundClose="door_close";float omega=0.0;vector axis;rotation closedRot;rotation openRot;integer swinging;integer open;sound(string name){    if(llGetInventoryType(name)==INVENTORY_SOUND)    llTriggerSound(name,1.0);}openDoor(integer yes){    if(yes) sound(soundOpen);    vector useAxis=axis;    open=yes;    if(!yes) useAxis=-axis;    llSetTimerEvent(openingTime/(float) steps);    llTargetOmega(useAxis,omega,1.0);}go(){    if(swinging==0)    {        if(!open)        {            axis=<0.0,0.0,1.0>/llGetRootRotation();            closedRot=llGetLocalRot();            if(world)            openRot=llGetRot()*llEuler2Rot(<0.0,0.0,openingAngle>*DEG_TO_RAD)/llGetRootRotation();            else            openRot=closedRot*llEuler2Rot(<0.0,0.0,openingAngle>*DEG_TO_RAD);        }        swinging=steps;        openDoor(!open);    }}rotation slerp(rotation source,rotation target,float amount){    return llAxisAngle2Rot(llRot2Axis(target/=source),amount*llRot2Angle(target))*source;}default{    state_entry()    {        swinging=0;        open=FALSE;        omega=TWO_PI/360*openingAngle/openingTime;        llTargetOmega(ZERO_VECTOR,1.0,1.0);        llListen(200,"","","");    }    touch_start(integer dummy)    {        go();    }    collision_start(integer dummy)    {        go();    }    listen(integer channel, string name, key id, string message)    {        if(message =="open")        {            go();        }    }    timer()    {        if(swinging>0)        {            swinging--;            if(swinging!=0)            {                float amount=(float) swinging/(float) steps;                if(open)                amount=1.0-amount;                llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,slerp(closedRot,openRot,amount)]);                return;            }            llTargetOmega(axis,0.0,0.0);            if(open)            {                llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,openRot]);                llSetTimerEvent(autocloseTime);            }            else            {                llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,closedRot]);                sound(soundClose);                llSetTimerEvent(0.0);            }        }        else // autoclose time reached        {            llSetTimerEvent(0.0);            openDoor(!open);            swinging=steps;        }    }}

Next, when the pads say "open" the door shall open only if it is not open
You just don't want to call the go() routine if the door is open

    listen(integer channel, string name, key id, string message)    {        if(message =="open" && !open)        {            go();        }    }

This modification will act like that
Do not get confused by the fact that you have a message and a variable both called open

  • Like 1
Link to comment
Share on other sites

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