Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Door swing  

swing

swing.lsl

Category: Door
By : Eloise Pasteur
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for swing
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. swing_1.lsl
1
2 // Swing script by Eloise Pasteur.
3 // Sold full perms by her - but please make at LEAST no mod before you pass it on
4 // Please only pass on in items for sale, not as the bare script.
5 // This script is as end-user friendly as possible. Moving the swing will make it reset to it's new position and orientation. Occasionally JUST rotating it won't work, so in that case you will need to nudge it sideways just a little (1mm will do). This is a quirk of LSL and it intermittent.
6 // Put this script in the pivot - the thing the swing swings around (it doesn't have to be a long rod). That needs to be the root of the prim set that actually swings - if you want/need a frame that needs to be a separate item. SL doesn't yet allow us hierarchical linking.
7
8 // Play with these bits - the orange comments tell you what's going on with each line I hope.
9
10 integer swing=FALSE; //So it starts out NOT swinging
11 float time=0.4; //Decreasing this (on it's own) makes the swing move FASTER and vice versa
12 integer steps=5; //The total number of steps in the swing's path. More steps=smoother swing. More steps (alone) means slower swing too - time for a complete swing cycle is steps * time (so 4.8 s with the default settings).
13 integer swingDegrees = 20; //How far from the vertical the swing moves
14
15 //If you play from here on down you might break the script. Do so at your own risk. There are no comments - just to encourage you NOT to play.
16
17 integer i=1;
18 float swingRad;
19 vector normal;
20
21 rotation Inverse(rotation r)
22 {
23 r.x = -r.x;
24 r.y = -r.y;
25 r.z = -r.z;
26 return r;
27 }
28 rotation GetParentRot()
29 {
30 return Inverse(llGetLocalRot())*llGetRot();
31 }
32 SetLocalRot(rotation x)
33 {
34 llSetRot(x*Inverse(GetParentRot()));
35 }
36
37 default
38 {
40 {
41 normal = llRot2Euler(llGetRot());
42 swingRad=DEG_TO_RAD*swingDegrees;
43 llSetTouchText("Swing");
44 }
46 {
47 if(swing)
48 {
49 swing=FALSE;
50 llSetTouchText("Swing");
51 }
52 else
53 {
54 swing=TRUE;
55 llSetTouchText("Stop Swing");
56 llSetTimerEvent(time);
57 }
58 }
59 timer()
60 {
61 float stepOffset=(float)i/steps*TWO_PI;
62 if(i>steps) i=1;
63 if(swing==FALSE && (i==steps || i==steps/2))
64 {
65 llSetTimerEvent(0.0);
66 SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));
67 } else
68 {
69 SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));
70 i++;
71 }
72 }
74 {
75 normal=llRot2Euler(llGetRot());
76 }
77 }// END //

Back to the Best Free Tools in Second Life and OpenSim.