Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotating a door along a circular path

Kyleus Musketeer
Registered User
Join date: 15 Oct 2005
Posts: 5
02-18-2006 22:21
I have a round room and a door (actually a small wall section) that I want to slide open on clicking and after some time close automatically. The problem I'm having is that the door always orients itself facing southwest. What do I need to add to make the door work correctly where ever the owner places it? -- Thanks in advance!

My script so far:

// circular sliding door script

// SETTINGS
float TIMER = 10.0; // seconds before closing door
// set to 0 to disable automatic closing

vector gPos; // door position (objects move a tiny amount away
// from their position each time they are rotated,
// thus we need to workaround this by resetting
// the position after rotating)

door(integer open)
{
if (open) {
vector eul = <0,0,20>; //degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot(eul); //convert to quaternion
llSetRot(quat); //rotate the object
}
else { // close
vector eul = <0,0,-20>; //degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot(eul); //convert to quaternion
llSetRot(quat); //rotate the object
}
}

default // first time startup
{
state_entry()
{

llSetPos(llGetPos());
llSetObjectName("Sliding Door";);
llSetObjectDesc("with circular sliding action";);
gPos = llGetPos(); // remember where we're supposed to be
llSay(0, "door is initialized";);
door(TRUE);
state closed;
}
}


state closed { // door is closed
on_rez(integer start_param) {
gPos = llGetPos();
}

state_entry() {
door(FALSE);
}

touch_start(integer total_number) {
state open;

}

moving_end() { // done moving me around, store new position
gPos = llGetPos();
}
}

state open { // door is open
on_rez(integer start_param) {
gPos = llGetPos();
state closed;
}

state_entry() {
llSetTimerEvent(TIMER);
llSetPos(gPos); // rotation drift workaround
door(TRUE);
}

touch_start(integer num) {
state closed;
}

timer() { // auto-close
state closed;
}

moving_start() { // close when being moved
state closed;
}

state_exit() {
llSetTimerEvent(0);
}
}
Kyleus Musketeer
Registered User
Join date: 15 Oct 2005
Posts: 5
Never Mind... I found my own workaround
02-19-2006 17:19
// circular sliding door script by Kyleus Musketeer
// designed to rotate rounded doors (cylinder sections)

default
{
touch_start(integer total_number)
{
// Door action
// a rotation of 20 degrees around the z-axis
rotation z_20 = llEuler2Rot( <0, 0, 20 * DEG_TO_RAD> ); //counter-clock
rotation new_rot = llGetRot() * z_20; // compute global rotation
llSetRot(new_rot); // orient the object accordingly
// llSay(0, "Door open.";);
llSetTimerEvent (10); // set timer for 10 seconds
}
timer() // wait set time
{
// a rotation of 20 degrees the other way
rotation z_20 = llEuler2Rot( <0, 0, -20 * DEG_TO_RAD> ); //clock-wise
rotation new_rot = llGetRot() * z_20; // compute global rotation
llSetRot(new_rot); // orient the object accordingly
// llSay(0, "Door closed.";);
llResetScript();
state default;
}
}