Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

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 open
vector r_closed = <0.0, 0.0, 0.0>; // and when it's in the closed state


integer 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.
_____________________
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
09-16-2006 22:08
/54/88/138014/1.html
_____________________
i've got nothing. ;)
Phineas Flanagan
Registered User
Join date: 25 Feb 2007
Posts: 65
04-21-2007 20:20
I was hoping this would solve a problem I've been having.

I made a house and used the common "Door Script" and much to my horror, when I linked it all together the door opened the entire house. I now know why it does this, but am hard-pressed to figure out a good way to fix it. (I want to be able to sell the house with the door already attached and positioned, because not everyone likes or is good at editing).

This code here would work in that it only rotates the single prim, but the rotation isn't right for a door - it is rotating around the center instead of the edge. Even if I set the cut path begin and end like you said to. Someone I know figured out how to use quaternions to achieve something similar, but that requires a 'hinge' as a reference for the door and a listener, which would just add unnecessary lag.

Is there no easy way to do this?
Astria Heron
Registered User
Join date: 11 Aug 2007
Posts: 0
08-15-2007 16:19
This is great EXCEPT, when you rotate the object, you have to go back into the script and change the rotaton values at the top unless I am missing something?

For example, I made a cabinet and put this in the door, it worked perfectly. But then, I rotated the cabinet to position it better in a room, and the door once clicked went back to the open and closed states as though the object it was attached to had never been rotated.

A little problematic for me because I was hoping to use it in furniture that I sell.

If anyone else knows of a script which will:

Open a door
Work in multiple doors linked to the same object
Adjust its position relative to its state after its been moved.

Please let me know!!