Jump to content
Sign in to follow this  
Void Singer

Simple Hinge Action

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

Share this post


Link to post
Share on other sites

That's great Void.

A question: Why do you recommend that the root prim is a pathcut cube? Or why is it important what type/shape the root is?

- Luc -

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

That just said 'wosh' as it flew past me... :o

Gonna have to get out my hammer and do some building this evening to see if I can comprehend what you are saying by actually trying it out.... :D

Thanks, tough.

- Luc -

Share this post


Link to post
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

Share this post


Link to post
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 -

Share this post


Link to post
Share on other sites

heh, and I totally misread your meaning

just goes to show that sometimes a lot more thought goes into some things that appear simple, and sometimes even simpler things get completely overlooked

Share this post


Link to post
Share on other sites

Actually the beauty of this sort of "door" is that it IS only one prim. No need for a hinge prim. For many folks prim pinching is a way of life so every prim you can cut out of the equation is a very good thing. :)

  • Like 1

Share this post


Link to post
Share on other sites

So what should the code look like in order to get the 'hinge' action?

 

Where do the alternative path-cut values go?

 

Sorry total noob here

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.  

Share this post


Link to post
Share on other sites

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.)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...