Jump to content

Why do all door scripts not work for me??


Lash Carver
 Share

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

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

Recommended Posts

So I'm trying a bunch of door scripts right now and for some reason none of them are working for me! 90% of them just rotate in the center instead of rotating AND moving to the side. Am I missing something?

I have a multi prim door... the scripts rotate in the center. I take the door down to 1 prim and link it to walls and stuff (not setting the door to root) and the door still rotates in the center.

I guess what I'm looking for is a door script for multi prims (door handle and stuff) which isn't linked to the house which calculates it's current rotation and simply adds 90 degrees and adjusts position so it's not in the middle! Can anybody help?

Link to comment
Share on other sites

Rotating a prim with LSL rotates that prim on its center. So most one-prim doors are cut in a way that leaves only half the prim visible, and the true center of the door is at the 'hinge edge'

Multiprim hinged doors use a 'hinge prim' as the root prim of the door. Again, the door rotates on the center of that root prim, and its true center is at the desired point of rotation. For your unlinked, multiprim door, just make sure the root prim of the door has its center at the hinge edge. Placing a slender cylinder prim along that edge and making it the root is the easiest way to do that.

Doors that have to be linked to a building either have to be one-prim doors, so the script in the door prim rotates the door and not the building, or require much more complicated scripting to read the position and orientation of the root prim of the building they are linked to, and base the door's rotation on that coordinate data. It is much more complicated to make a linked door open and close properly. So simple free scripts usually require the door to remain un-linked.

Link to comment
Share on other sites

oh wow I didn't know that was the general rule, I thought people would just use scripts to also adjust the position to make it look like it swung open. hmm ok thanks :)

 

If anybody does have a script that adjusts position without needing to slice the door, I'd definitly try it. 

Link to comment
Share on other sites

Door scripts that use cut prim doors are perhaps the simplest scripts you can find, and the most reliable.  My favorite is Void Singer's Simple Hinge Action, which I have modified and adapted many times to different situations. 

Cutting or slicing is not really much work.  Assuming that you want the door to swing around its local Z axis, you have two choices:

1.  To make the door swing from the center of its hinge side, set Path Cut E = 0.125 and Path Cut B = 0.875.

2.  To make the door swing from the edge of its hinge side, the way most RL doors do, set Path Cut E = 0.375 and Path Cut B = 0.625.

If you want the door to swing around a horizontal axis (X or Y), set Slice B or Slice E to 0.5 to cut either the bottom or the top of the prim off.  A horizontally-hinged door (a drawbridge or a cat door) always swings from the center of the cut edge.

Link to comment
Share on other sites

While I agree with Rolig that it's almost always best to use Void's door script and a cut prim, there are some occassions when this isn't practicable.   When you do find you have to move the rotation offset of an uncut prim, this is the basic method.    You shouldn't need to use it that often, but it's good to know how to do it.

Note that it assumes we start with a normally rotated prim (that is, you're doing the initial calculations with the prim rotated at <0,0,0>, or as it is when it's first rezzed.    It also assumes that the door is either a single uncut box or that it's the root prim of a more complex freestanding door (it will complain if it's not).   It also assumes we start with a closed door that opens outwards.

If you need to alter the way the door pivots, play around with making either or both the x and y values of the offset vector negative, and/or the z value of the offset vector you use to calculate z90;    This sounds complicated but it's not -- simple trial and error should tell you what to do pretty quickly.

 

integer myLinkNumber;rotation z90;vector offset;vector size;default{	state_entry()	{		myLinkNumber = llGetLinkNumber();		if (!~llListFindList([0,1],[myLinkNumber])){//make sure it's either an unlinked prim or the root			llOwnerSay("Please make sure this script is in the root prim of the door, which should be the main, uncut, door prim that you want to turn on its edge");			return;		}		z90 = llEuler2Rot(<0.0,0.0,90.0>*DEG_TO_RAD); // 90 degrees on the z axis, as a quaternion		size = llList2Vector(llGetLinkPrimitiveParams(myLinkNumber,[PRIM_SIZE]),0); // size of root prim, which we hope is the uncut door prim		offset = <(size.x*0.5), (size.y*0.5),0.0>;		//hinges on the edge between sides 2 and 3, that is, if you are standing facing side 2 (the side the red arrow comes out of when the prim is first rezzed, it's hinged on your right, and it's going to open outwards	}	changed(integer change)	{		if (change & CHANGED_LINK || change & CHANGED_SCALE){			llResetScript();		}	}	touch_start(integer total_number)	{		if (llDetectedLinkNumber(0)==myLinkNumber){			list l = llGetLinkPrimitiveParams(myLinkNumber,[PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);			vector LocalPos = llList2Vector(l,0);			rotation LocalRot = llList2Rot(l,1);			llSetLinkPrimitiveParamsFast(myLinkNumber,[PRIM_POS_LOCAL, LocalPos +(offset-offset*z90)*LocalRot,				PRIM_ROT_LOCAL,z90*LocalRot]);			z90=ZERO_ROTATION/z90;//reverse the value of the rotation, so the next touch either closes or opens the door		}	}}

 

For a detailed explanation of how this works, see Grandma Bates' two excellent short tutorials, Basic Introduction to Rotations and Introduction to Rotations with Translations, which are a great help in demystifying LSL rotations.

  • Like 1
Link to comment
Share on other sites


Lash Carver wrote:

I guess what I'm looking for is a door script for multi prims (door handle and stuff) which isn't linked to the house which calculates it's current rotation and simply adds 90 degrees and adjusts position so it's not in the middle! Can anybody help?

This llSetKeyFramedMotion example in the wiki fills your request exactly

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

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