Jump to content

Simple Hinge Action


Void Singer
 Share

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

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

Recommended Posts

Doors, Gates, Lids, anything with a simple hinge

/*//( v7-D Simple Hinge Action )--//*/
/*//-- Works At ANY Angle --//*/

/*//-- NOTES:
 works in ANY single prim door, linked or un-linked
 works in multi-prim doors NOT linked to a larger structure
 Never needs reset (even after moving/rotating)
//*/
/*//-- REQUIREMENTS:
Root should either be a cylinder (to represent a hinge) or half cut prim;
 I suggest Box, pathcut start=.125, end=.625
//*/
/*//-- CAVEAT:
 Single prim doors are limited to 5m width
 Treats current position as closed when reset
//*/
/*//-- USERS MODIFY HERE v --//*/ integer gIntSwing = 90; /*//-- use -# to reverse the direction of swing, eg. -90; --//*/ rotation gRotSwing; default{ state_entry(){ gRotSwing = llEuler2Rot( <0.0, 0.0, (float)gIntSwing * DEG_TO_RAD> ); } touch_end( integer vIntNul ){ llSetLocalRot( (gRotSwing = (ZERO_ROTATION / gRotSwing)) * llGetLocalRot() ); } } /*//-- IF Redistributing as-is:
Please leave script full permissions & include all comments so that others may learn and use
//*/

to use in lids, create lid as above, move/rotate (via object edit) into  place, done.

to create realistic hinge action:  path-cut start = .375, end = .625 (preferred)  OR   path-cut start = .125, end = .375

(remove gIntSwing and state_entry if you pre-calculate and assign the value of gRotSwing)



  • Like 5
  • Thanks 1
Link to comment
Share on other sites

Ya know, that a very good question and it's actually based on a bit of experience....

the cube (should read box, will edit that) because it's a flat surface on all sides, even after it's cut, so that it retains it's basic shape.

the path cuts suggested allow the inside/outside (top/bottom for lids) to face along the x axis which makes modifications like automatic opening and direction of swing for reversible doors a little easy to code for...and because some users are unfamiliar with the build tools so may not know what to modify to get a "half-cut" that the code requires, and because cuts start from the corner not the side as some might expect (so it helps counteract the non obvious nature)

ETA:
the inworld build tools actually conflict on cube vs box, the create tab tooltip calls it a cube, and the edit tab prim type refers to it as a box. however all the scripting commands also refer to it as a box, so that's what I'm going to go with.

  • Like 1
Link to comment
Share on other sites

... the simple answer ...

Prims rotate around their centre, which would be a very strange thing for a door to do.  When a box is cut in half like this the centre 'looks' as if it is at the side (because you can't see the rest which has been cut away).  So the door 'looks' like it is rotating around the edge, on a hinge.

  • Like 1
Link to comment
Share on other sites

Ahhhh. Now I get it! Thanks Peter!

I read it as if the path cut prim was the hinge (root prim) to which you attached the actual door (a second prim linked to the root prim). Duh!!!! (I actually know about the rotating around the centre in a one prim door. I just didn't connect the dots properly)

- Luc -

Link to comment
Share on other sites

  • 9 months later...

The code looks exactly like it is now.  No change whatsoever.  Path cut values are used for shaping your door, using your Build/Edit tool in world.  The whole idea of this door script and others built on this theme is that you create a door by cutting a rectangular prim in half, so that its hinge is along the cut edge.  Otherwise, since a prim always rotates around its central axis (in this case, its Z-axis), you'd have a door that looks like a butterfly valve instead of a normal door.

Link to comment
Share on other sites

  • 2 years later...
  • 3 weeks later...

Several people have asked if there is a way to reduce the number of scripts in a building by controlling all doors centrally from a single script.  Rather than write a new script to do that, I have modified Void's simple hinge script as an example of how it might be done.

// Control many doors in the same linkset -- Rolig Loon -- March 2015// Application of Void Singer's SImple Hinge Action to control several doors//   in the same building independently from a single script.//   All doors must be named "door"./*//( v7-D Simple Hinge Action )--//*//*//-- Works At ANY Angle --//*//*//-- NOTES: works in ANY single prim door Never needs reset (even after rotating)//*//*//-- REQUIREMENTS: Root must either be a cylinder (to represent a hinge) or cut prim; I suggest cube, pathcut start=.125, end=.625//*//*//-- CAVEAT: Single prim doors are limited to 5m width Treats current position as closed when reset//*/ /*//-- USERS MODIFY HERE v --//*/integer gIntSwing = -90;/*//-- use -# to reverse the direction of swing, eg. -90; --//*/rotation gRotSwing;integer gDoor;list gDoors;default{    state_entry()    {        gDoors = [];        integer i = llGetNumberOfPrims();        while(i)        {            if (llStringTrim(llToLower(llGetLinkName(i)),STRING_TRIM) == "door")            {                gDoors += [i];            }            --i;        }        gRotSwing = llEuler2Rot( <0.0, 0.0, (float)gIntSwing * DEG_TO_RAD> );        state running;    }}state running{            touch_end( integer num )    {        gDoor = llDetectedLinkNumber(0);        if (~llListFindList(gDoors,[gDoor]))        {            state active;        }    }}state active{    state_entry()    {        llSetTimerEvent(5.0); // Set timer to close the door in 5 seconds        rotation RotLocal = llList2Rot(llGetLinkPrimitiveParams(gDoor,[PRIM_ROT_LOCAL]),0);        llSetLinkPrimitiveParamsFast(gDoor,[PRIM_ROT_LOCAL,(gRotSwing = (ZERO_ROTATION / gRotSwing)) * RotLocal] );    }        touch_end(integer num)    {        if (~llListFindList(gDoors,[llDetectedLinkNumber(0)]))        {            rotation RotLocal = llList2Rot(llGetLinkPrimitiveParams(gDoor,[PRIM_ROT_LOCAL]),0);            llSetLinkPrimitiveParamsFast(gDoor,[PRIM_ROT_LOCAL,(gRotSwing = (ZERO_ROTATION / gRotSwing)) * RotLocal] );            llSetTimerEvent(0.0);            state running;        }    }                    timer()    {               rotation RotLocal = llList2Rot(llGetLinkPrimitiveParams(gDoor,[PRIM_ROT_LOCAL]),0);        llSetLinkPrimitiveParamsFast(gDoor,[PRIM_ROT_LOCAL,(gRotSwing = (ZERO_ROTATION / gRotSwing)) * RotLocal] );        llSetTimerEvent(0.0);        state running;    }        }

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

You could certainly add code to the script to give doors speed control, but I would not recommend it.  As you can see, the doors move with llSetLinkPrimitiveParams, which is not designed to have a native speed control. You would need to contrive an iterative sequence with a timer event. In my opinion, that's more trouble than it's worth.  If I were faced with a similar problem, I would use a completely different system. The old Toy Wylie Smooth Door script is one possible model, but I would probably use Keyframed Motion, which is designed for exactly that sort of control.  You could not link the doors, of course, but you could certainly control several doors from the same remote trigger.

As interesting as those alternatives are, this is not really the place to discuss them.  

Link to comment
Share on other sites

  • 5 weeks later...

This post might be an oldie, but the script works like a charm and was exactly what I needed for my gate. Thanks!



(The root prim should be apparent in the picture. No modification needed; I just copied and pasted the script as written into a new script and it worked perfectly the first time.)

Link to comment
Share on other sites

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