## Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

# Discussion: Nice, simple rotation script. Can be linked to parent. Great for doors.

Sue Stonebender
Piano Craftsman
Join date: 7 Jan 2005
Posts: 219
09-16-2006 21:46
Here's a nice simple script that you can pop into a child prim that you wish to rotate. Go ahead and link it to the main primset. It doesn't require a prim hinge, nor does it need to be unlinked. It gives a nice, smooth rotation from the first target through to the second.

(Huge tip of the hat to my own mentor, Jillian Callahan, without whom my own library would be an abominable mess. She rescued me when I was trying to do this a long time ago.)

All you have to change is the top code. The first line asks you to identify what the prim's rotation will be relative to the parent prim when it's open. If the parent is set to <0,0,0> then you just take a peek at the prim you're rotating to see what the rot is when you've got it set to where you would want it to be in the open position (otherwise, adjust according to the parent). Similarly, the line below asks you what the rotation should be when this prim is in the closed state, again relative to the parent prim's rotation.

The third statement allows you to indicate whether or not this prim should be in the open or closed state when the object it's attached to is first rezzed.

If this is a cupboard with handles, you'll need to pass a linked message in so that they can talk to each other and each will know when the other's been touched so that their open and closed states are in synch.

This is a staple in my own library. Couldn't do without it.

CODE
`vector r_open = <0.0, 90.0, 0.0>; // This prim's rotations in degrees relative to root prim when this prim is openvector r_closed = <0.0, 0.0, 0.0>; // and when it's in the closed stateinteger close_on_rez = TRUE; // Change to false to have the prim open on rez// ======================================================= Nothing from here down needs modding.rotation LocalRot(rotation localrot){    rotation LocRot = localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot());    return LocRot;}open(string door){    llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_open * DEG_TO_RAD))]);}close(string door){    llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_closed * DEG_TO_RAD))]);}default {    state_entry()    {        if (close_on_rez)        {            state closed;        }        else        {            state opened;        }    }        on_rez(integer rez)    {        llResetScript();    }}state opened{    state_entry()    {        open("left");    }        on_rez(integer rez)    {        llResetScript();    }        touch_start(integer n)    {        state closed;    }    }state closed{    state_entry()    {        close("left");    }        on_rez(integer rez)    {        llResetScript();    }        touch_start(integer n)    {        state opened;    }    }`

Lovely if you're using a nice round lid on a chest. If you're using it as a door and you want it to rotate around the axis, be sure to cut a box prim's path to begin at 0.375 and end at 0.875. This gives the illusion of the door rotating at it's edge, rather than in it's center of gravity.

Remember, this is just an example. You will have to change the vectors to match the rotations you want for the prim you are using relative to it's own parent.

Cheers
Sue.
_____________________
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
09-16-2006 22:08
/15/e4/138010/1.html
_____________________
i've got nothing.
Soyo Kongo
Registered User
Join date: 22 Oct 2005
Posts: 11
09-21-2006 20:56
Nice script. I found a use for it but how can one set it to automanicly rorate to it's orginal postion after x seconds?
David DiPrima
Registered User
Join date: 29 Sep 2006
Posts: 15
Opening door
12-28-2006 11:22
This script savedme from a huge headache thank you. This one is a keeper. Would it be a simple matter of creating handles that move too? I've tried variations on the provided script, but I think some kind of setpos command will be need as well. I may just leave the handle off too save more headaches. Thank you for your time.
Xavier Dieffenbach
Registered User
Join date: 21 Oct 2006
Posts: 1
Thanks!
01-08-2007 16:10
Argh it was a royal pain getting my door to work properly til i found this. Thanks so much!
Guano Asano
Registered User
Join date: 2 Dec 2006
Posts: 1
I know I'm doing something wrong
01-14-2007 13:09
I am trying to combine the best features of four different scripts into one that does exactly what I need. What I need is for multiple doors in a fully linked house to open and close correctly after the house has been moved and rotated.

I have the doors responding to their touches with the correct open/close commands but the rotations and translations are not going as planned. Things seem to work but then after moving/rotating the house the doors start to move around the house.

Could someone please post what each of the rotations & translations in this (or another) script is doing so I can understand how all the pieces fit together?

Thanks!
Eowrah Enoch
Green Smurf
Join date: 9 Mar 2007
Posts: 6
10-06-2007 03:25
Great script, but how do I do this:
From: someone
If this is a cupboard with handles, you'll need to pass a linked message in so that they can talk to each other and each will know when the other's been touched so that their open and closed states are in synch.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
10-06-2007 16:47
great script, but for doors and lids(or anything with a single hinge )there IS a simpler solution.... simple building trick

create a cube, set path cut begin 0.125, end 0.625

in the script it's just

rotation base = llGetRot();
rotation open = base.y += 90; (chage to z for lids)

to open, call
llSetRot( open );

to close, call
llSetRot( base );

CAVEAT: prim is limited to 5m length from hinge
Mitzy Shino
can i haz ur stufz?
Join date: 15 Dec 2006
Posts: 409
10-29-2007 02:57
From: Sue Stonebender

Lovely if you're using a nice round lid on a chest. If you're using it as a door and you want it to rotate around the axis, be sure to cut a box prim's path to begin at 0.375 and end at 0.875. This gives the illusion of the door rotating at it's edge, rather than in it's center of gravity.

Remember, this is just an example. You will have to change the vectors to match the rotations you want for the prim you are using relative to it's own parent.

I LOVE YOU, thank you, thank you, thank you!

I was trying to work out how to smoothly rotate the entire prim, and my numbers are different but your suggestion worked wonders, my cage no longer has a door that twists in the middle, Yay!
Mitzy Shino
can i haz ur stufz?
Join date: 15 Dec 2006
Posts: 409
10-29-2007 03:32
From: Void Singer

rotation base = llGetRot();
rotation open = base.y += 90; (chage to z for lids)

I LOOOOOOOOOOOOOOOOVE you too, thats so much simpler than what I was doing, lol.

rotation open.y = base.y += 90;

I suspect thats the right thing to do and it works, but in case you haven't worked it out I'm a scripting newbie and have no real idea what I am doing
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
10-30-2007 03:59
From: Mitzy Shino
I LOOOOOOOOOOOOOOOOVE you too, thats so much simpler than what I was doing, lol.

rotation open.y = base.y += 90;

I suspect thats the right thing to do and it works, but in case you haven't worked it out I'm a scripting newbie and have no real idea what I am doing

lol that's what I get for not checking my spellign

here's an even simpler version, works at any angle, even after moving it

CODE
` //--// v7-D Type 1 Door Script  //--// //--// Works At ANY Angle	   //--////-- works in ANY single prim door, linked or un-linked//-- works in muti prim doors NOT linked to a larger structure//-- REQUIREMENTS: a cut root prim, suggest cube, pathcut start=.125, end=.625//-- CAVEAT: single prim doors are limited to 5m width //--// USERS MODIFY HERE vinteger  vgVecDoorSwing = 90;//-- use -# to revers the direction of swing -eg. -90rotation vgRotDoorSwing;default{  state_entry(){	vgRotDoorSwing = llEuler2Rot( <.0, .0, (float)vgVecDoorSwing> * DEG_TO_RAD );	state vsMain;  }}state vsMain{  touch_start( integer vIntTouches ){	 //- small hack to reverse direction of swing and	 //- avoid lsl funkiness regarding rotation division	vgRotDoorSwing.s *= -1;	llSetLocalRot( vgRotDoorSwing * llGetLocalRot()  );  }}    `

EDIT: also works for lids, just create a door, then rotate it on its side
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Eristic Strangelove
Registered User
Join date: 16 Nov 2005
Posts: 39
12-01-2007 07:48
From: Void Singer

here's an even simpler version, works at any angle, even after moving it

CODE
` //--// v7-D Type 1 Door Script  //--// //--// Works At ANY Angle	   //--////-- works in ANY single prim door, linked or un-linked//-- works in muti prim doors NOT linked to a larger structure//-- REQUIREMENTS: a cut root prim, suggest cube, pathcut start=.125, end=.625//-- CAVEAT: single prim doors are limited to 5m width //--// USERS MODIFY HERE vinteger  vgVecDoorSwing = 90;//-- use -# to revers the direction of swing -eg. -90rotation vgRotDoorSwing;default{  state_entry(){	vgRotDoorSwing = llEuler2Rot( <.0, .0, (float)vgVecDoorSwing> * DEG_TO_RAD );	state vsMain;  }}state vsMain{  touch_start( integer vIntTouches ){	 //- small hack to reverse direction of swing and	 //- avoid lsl funkiness regarding rotation division	vgRotDoorSwing.s *= -1;	llSetLocalRot( vgRotDoorSwing * llGetLocalRot()  );  }}    `

EDIT: also works for lids, just create a door, then rotate it on its side

This is exactly what i needed (thnx!) for a revolving (cylindrical) door and works great except that it occasionally decides to reverse its direction and spin anti-clockwise instead of clockwise (or vice-versa). This seems to happen when the script is copied or reset, like during a drag-copy of the original item. I can correct it again by editing the script but why does this happen?

Any ideas how I avoid this behaviour - or is it something i don't need to worry about since it will end up in a no-copy item?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-01-2007 10:25
From: Eristic Strangelove
This is exactly what i needed (thnx!) for a revolving (cylindrical) door and works great except that it occasionally decides to reverse its direction and spin anti-clockwise instead of clockwise (or vice-versa). This seems to happen when the script is copied or reset, like during a drag-copy of the original item. I can correct it again by editing the script but why does this happen?

Any ideas how I avoid this behaviour - or is it something i don't need to worry about since it will end up in a no-copy item?

what you're seeing isn't a reverse in direction, but a doubling or the same move direction when you reset the script. basicly it's trying to 'open' when it's already open.

the solution is not to copy the while it's already "open", or put the door in place BEFORE you drop the script in it. if you do happen to reset the script while it's open, simply rotating the door manually back into place will fix the problem.

EDIT: Eristic = Discordian reference? =)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Eristic Strangelove
Registered User
Join date: 16 Nov 2005
Posts: 39
12-01-2007 10:50
Ah, of course...that makes sense. Thnx for the response and the original script!
Bobbyb30 Zohari
SL Mentor Coach
Join date: 11 Nov 2006
Posts: 466
12-01-2007 10:58
Its good but it has no intermediate step, (like a 45 degree angle).

Otherwise good.
_____________________
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-01-2007 11:19
From: Bobbyb30 Zohari
Its good but it has no intermediate step, (like a 45 degree angle).

Otherwise good.

I'm guessing you want a smooth looking motion? as far as I can tell the 'door' still visibly moves, taking the shortest path of rotation to it's new position... so if you used 270 instead of -90 it would still appear to move -90... the physics engine seems to interpret it that way also (most of the time, the rest of the time it's treated as translocation)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Isebella Dallagio
Registered User
Join date: 15 Aug 2007
Posts: 5
but how do we add handles?
04-09-2008 02:36
how do we add handles to this? I've been looking everywhere for something like this, thank you :*