Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Open a Door Slowly?!

Diego Pannotia
Laronzo Fitzgerald
Join date: 14 Nov 2006
Posts: 37
02-23-2007 09:11
Hi guys, been looking around forums and generally not quite getting the info / understanding straight so thought I'd post the question : )

I have below a very Simple script for a door.. what I need to do is slow the rotation as it opens or closes, right down. The door is meant to simulate a 1stLife electric door which as you can imagine opens slowly... in say... about 5 seconds. How can I do this? Many thanks, Mark.

CODE

vector OpenRot = <0.00, 0.00, 192.25>;
vector ClosedRot = <0.00, 0.00, 281.00>;

default
{
state_entry()
{
state closed;
}
}

state closed
{
state_entry()
{
llSetRot(llEuler2Rot(ClosedRot * DEG_TO_RAD));
}

touch_start(integer N)
{
state open;
}
}


state open
{
state_entry()
{
llSetRot(llEuler2Rot(OpenRot * DEG_TO_RAD));
}

touch_start(integer N)
{
state closed;
}
}
Diego Pannotia
Laronzo Fitzgerald
Join date: 14 Nov 2006
Posts: 37
02-23-2007 09:31
If it's easier rather than do the whole rotate in one shot, could I do for example 10 little rotates? How would I accomplish that? Smoothness would be nice...
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-23-2007 09:44
The script you have is designed to 'just' change position immediately.
To slow it down and make it rotate slowly use a number of smaller steps, but be aware that llSetPos and llSetRot both incur a .2 second delay.

CODE

vector OpenRot = <0.00, 0.00, 192.25>;
vector ClosedRot = <0.00, 0.00, 281.00>;
vector delta;
integer steps = 10;

RotateDoor(vector startpos, vector offset)
{
integer i;

vector angle = startpos;
for(i=0;i< steps;++i)
{
angle += offset;
llSetRot(llEuler2Rot(angle * DEG_TO_RAD));
}
}

default
{
state_entry()
{
delta = OpenRot - ClosedRot;
delta /= steps;
state closed;
}
}

state closed
{
state_entry()
{
RotateDoor(ClosedRot, delta );
}

touch_start(integer N)
{
state open;
}
}


state open
{
state_entry()
{
RotateDoor(OpenRot, - delta );
}

touch_start(integer N)
{
state closed;
}
}
Diego Pannotia
Laronzo Fitzgerald
Join date: 14 Nov 2006
Posts: 37
02-23-2007 10:10
That's very efficient I like it very much!

The only problem I experience is that when opening the doors open clockwise about the axis with the script in it instead of anticlockwise and vice versa when closing....

How can we fix this?

Many thanks again,

Mark.
Max Pitre
Registered User
Join date: 19 Jul 2006
Posts: 370
02-23-2007 11:20
From: Diego Pannotia
That's very efficient I like it very much!

The only problem I experience is that when opening the doors open clockwise about the axis with the script in it instead of anticlockwise and vice versa when closing....

How can we fix this?

Many thanks again,

Mark.

Turn the one door prim upside down and adjust or redo the texture? Thats how I did it.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
02-23-2007 11:56
From: Diego Pannotia
That's very efficient I like it very much!

The only problem I experience is that when opening the doors open clockwise about the axis with the script in it instead of anticlockwise and vice versa when closing....

Mark.


The first two line of the script dscribe the start and stop orientation of the door. Change those values. rinse. repeat.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-23-2007 15:12
Swap the signs....
Diego Pannotia
Laronzo Fitzgerald
Join date: 14 Nov 2006
Posts: 37
02-26-2007 03:02
Ugh - what a hangover. So anyway. *sob* which signs? I can't for the life of me seem to do it myself. Tried swapping delta = in default state, tried swapping rotatedoor() in open/closed states, tried swapping angle += offset...
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
02-26-2007 05:23
This will cause a door to open smoothly at a desired speed, rather than in hard steps. It will have a tendency to momentarily "overshoot" the opened or closed positions depending on lag, since llSleep is only as accurate as sim load permits. This can be loosely compensated for by multiplying the optimal period ( AngleSwept / Speed ) by llGetRegionTimeDilation().

CODE

// Open state, 0 or 1
integer Open = FALSE;

// Closed and Open rotations, respectively
// These equate to Eulers of <0,0,0> and <0,0,90>, in degrees.
list Rotations = [ < 0., 0., 0., 1 >, < 0., 0., 0.7071, 0.7071 > ];

// Direction and speed of rotation when Closing and Opening, respectively.
// Negative = Clockwise
// Speed is in Radians-per-Second
list Directions = [ -1., 1. ];

default
{
state_entry()
{
llSetRotation( llList2Rot( Rotations, 0 ) );
}

touch_start(integer total_number)
{
// Toggle Open state
Open = !Open;

// Start rotating around Z axis in the appropriate direction
llTargetOmega( <0.,0.,1.>, llList2Float( Directions, Open ), 1. );

// Sleep while rotating, period = AngleSwept / Speed
llSleep( PI_BY_TWO );

// Stop Rotating
llTargetOmega( <0.,0.,0.>, 0., 0. );

// "Snap" to open or closed rotation
llSetRot( llList2Rot( Rotations, Open ) );
}
}
Diego Pannotia
Laronzo Fitzgerald
Join date: 14 Nov 2006
Posts: 37
chars
02-26-2007 08:11
Lovely thanks : )
Esch Snoats
Artist, Head Minion
Join date: 2 May 2006
Posts: 261
04-22-2007 16:28
I tried out the script that Deanna posted here and it works great for one door, but I have double doors and it absolutely freaks out on the second door. I don't know squat about coding, so can someone tweak the above script so that it works as the 2nd door in a double door set and open the same direction as the above script? Thank you!!!

E
Esch Snoats
Artist, Head Minion
Join date: 2 May 2006
Posts: 261
04-23-2007 22:40
Anyone? I've been trying to get this to work for days but no luck. :(
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-24-2007 00:54
From: Esch Snoats
Anyone? I've been trying to get this to work for days but no luck. :(



Define 'freaks out' ? Are the doors linked?
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
04-24-2007 04:35
These are the scripts for doors that are cut and not linked.

left door
CODE

// Open state, 0 or 1
integer Open = FALSE; // 0
integer gChannel = 100;
integer gDebug = TRUE;

// Closed and Open rotations, respectively
// These equate to Eulers of <0,0,0> and <0,0,90>, in degrees.
list Rotations = [ < 0., 0., 0., 1 >, < 0., 0., 0.7071, 0.7071 >];

// Direction and speed of rotation when Closing and Opening, respectively.
// Negative = Clockwise
// Speed is in Radians-per-Second
list Directions = [ -1., 1. ];
list whispers = ["open", "close"];


rotate (integer Open) {
// Start rotating around Z axis in the appropriate direction
llTargetOmega( <0.,0.,1.>, llList2Float( Directions, Open ), 1. );

// Sleep while rotating, period = AngleSwept / Speed
llSleep( PI_BY_TWO );

// Stop Rotating
llTargetOmega( <0.,0.,0.>, 0., 0. );

// "Snap" to open or closed rotation
llSetRot( llList2Rot( Rotations, Open ) );
}


default
{
state_entry()
{
llSetRot ( llList2Rot( Rotations, 0 ));
llListen(gChannel, "", "", "");
}

touch_start(integer total_number)
{
// Toggle Open state
Open = !Open;
llWhisper (gChannel, (string) Open);
rotate (Open);

}
listen( integer ch, string who, key id, string message ){
if (gDebug)
llOwnerSay ("listen message = " + message);
integer dir = (integer) message;
rotate (dir);
}
}



right door
CODE

// Open state, 0 or 1
integer Open = FALSE; // 0
integer gChannel = 100;
integer gDebug = TRUE;

// Closed and Open rotations, respectively
// These equate to Eulers of <0,0,0> and <0,0,90>, in degrees.
list Rotations = [ < 0., 0., 0.7071, 0.7071 >, < 0., 0., 0., 1 >];

// Direction and speed of rotation when Closing and Opening, respectively.
// Negative = Clockwise
// Speed is in Radians-per-Second
list Directions = [ 1., -1. ];
list whispers = ["open", "close"];


rotate (integer Open) {
// Start rotating around Z axis in the appropriate direction
llTargetOmega( <0.,0.,1.>, llList2Float( Directions, Open ), 1. );

// Sleep while rotating, period = AngleSwept / Speed
llSleep( PI_BY_TWO );

// Stop Rotating
llTargetOmega( <0.,0.,0.>, 0., 0. );

// "Snap" to open or closed rotation
llSetRot( llList2Rot( Rotations, Open ) );
}


default
{
state_entry()
{
llSetRot ( llList2Rot( Rotations, 0 ));
llListen(gChannel, "", "", "");
}

touch_start(integer total_number)
{
// Toggle Open state
Open = !Open;
string dir = (string) Open;
if (gDebug)
llOwnerSay ("touch_start dir = " + dir);
llWhisper (gChannel, (string) Open);
rotate (Open);

}
listen( integer ch, string who, key id, string message ){
if (gDebug)
llOwnerSay ("listen message = " + message);
integer dir = (integer) message;
rotate (dir);
}
}


Esch, I have got much pleasure out of your art gallery, so I don't mind doing this for you.

The two scripts are identical except for the order in the Directions and Rotations lists. This might need further modding if the two doors are to be identical.

I have set up a couple of cubes in the SE corner of Explorers Rangeland (next to my shed) where you can try this and copy it.

Edit: I have not cut these doors. I suspect I will need to do more work to line up the rotations and positions of the doors when they are.
Esch Snoats
Artist, Head Minion
Join date: 2 May 2006
Posts: 261
04-24-2007 06:11
From: Newgate Ludd
Define 'freaks out' ? Are the doors linked?


No they aren't linked. If I align the 2nd door to where it needs to be and click it, it will open fine, until I click it to close, then it will go to the closed position and then completely bypass it and realign itself to be in the same direction as the 1st door. Then from that point on it opens as if it's the other door. Sometimes it freaks and will go completely in circles too, lol.
Esch Snoats
Artist, Head Minion
Join date: 2 May 2006
Posts: 261
04-24-2007 06:11
Thank you very much Ed!!!! I will check these out right now!!