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__for_pivot_as_root_updated  

Swing__for_pivot_as_root_updated

Swing - for pivot as root

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

the Zip file

Download all files for Swing__for_pivot_as_root_updated
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Swing__for_pivot_as_root_updated_1.lsl
1 // 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.
2
3 // Play with these bits - the orange comments tell you what's going on with each line I hope.
4
5 integer swing=FALSE; //So it starts out NOT swinging
6 float time=0.1; //Decreasing this (on it's own) makes the swing move FASTER and vice versa
7 integer steps=20; //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).
8 integer swingDegrees = 30; //How far from the vertical the swing moves
9
10 //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.
11
12 integer i=1;
13 float swingRad;
14 vector normal;
15
16 rotation Inverse(rotation r)
17 {
18 r.x = -r.x;
19 r.y = -r.y;
20 r.z = -r.z;
21 return r;
22 }
23 rotation GetParentRot()
24 {
25 return Inverse(llGetLocalRot())*llGetRot();
26 }
27 SetLocalRot(rotation x)
28 {
29 llSetRot(x*Inverse(GetParentRot()));
30 }
31
32 default
33 {
35 {
36 normal = llRot2Euler(llGetRot());
37 swingRad=DEG_TO_RAD*swingDegrees;
38 llSetTouchText("Swing");
39 }
41 {
42 if(swing)
43 {
44 swing=FALSE;
45 llSetTouchText("Swing");
46 }
47 else
48 {
49 swing=TRUE;
50 llSetTouchText("Stop swing");
51 llSetTimerEvent(time);
52 }
53 }
54 timer()
55 {
56 float stepOffset=(float)i/steps*TWO_PI;
57 if(i>steps) i=1;
58 if(swing==FALSE && (i==steps || i==steps/2))
59 {
60 llSetTimerEvent(0.0);
61 SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));
62 } else
63 {
64 SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>));
65 i++;
66 }
67 }
69 {
70 normal=llRot2Euler(llGetRot());
71 }
72 }

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