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
Animation Walking_Script  

Walking_Script

Walking Script.lsl

Category: Animation
By : Zepp Zaftig
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Walking_Script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Walking_Script_1.lsl
1
2 //Copyright 2006 Zepp Zaftig - GNU Lesser General Public License http://www.gnu.org/copyleft/lesser.html
3 //This script or any modified versions of it may not be distributed without source code.
4
5 //Settings
6 //Edit these to configure the script
7 string WALKANIM = "female_walk"; //Name of the walk animation to use
8 string FLYANIM = "fly"; //Flying animation
9 string HOVERANIM = "hover"; //Hover animation
10 string UPANIM = "hover_up"; //Flying up animation
11 string DOWNANIM = "hover_down"; //Flying down animation
12 integer WALKSPEED = 1; //Change to an integer higher than 1 to walk faster
13 integer FLYSPEED = 10; //How many times faster the flying speed should be compared to default speed
14 integer PHANTOM = TRUE; //Set to TRUE for walking through solid objects, FALSE to disable
15 integer TOUCHABLE = TRUE; //Rotate 90 degrees on touch when set to TRUE
16 //End settings
17
18 float zoffset;
19 integer flying = FALSE;
20
21 default {
22 state_entry() {
23 llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
25 vector avatarsize = llGetAgentSize(llGetOwner());
26 zoffset = avatarsize.z / 1.3;
27 llSitTarget(<0, 0, -0.5>, ZERO_ROTATION);
28 llCollisionSound("", 0);
29 }
30
31 changed(integer change) {
32 if(change & CHANGED_LINK) {
33 key agent = llAvatarOnSitTarget();
34 if(agent) {
35 if(agent != llGetOwner()) {
36 llUnSit(agent);
37 } else {
40 }
41 } else {
46 }
47 }
48 }
49
51 if(perm) {
52 llStopAnimation("sit");
53 llStartAnimation("stand");
56 }
57 }
58
59 control(key id, integer level, integer edge) {
60 //Any button pressed
61 if(edge & level) {
63 llStopAnimation(HOVERANIM);
64 }
65
66 //Forward or backwards pressed
67 if(edge & level & (CONTROL_FWD|CONTROL_BACK)) {
68 if(flying == TRUE) {
69 llStartAnimation(FLYANIM);
70 } else {
71 llStartAnimation(WALKANIM); //Start the walk animation
72 }
73 }
74 //All buttons released
75 if((~level & CONTROL_FWD) && (~level & CONTROL_BACK) && (~level & CONTROL_RIGHT) &&
76 (~level & CONTROL_LEFT) && (~level & CONTROL_ROT_RIGHT) && (~level & CONTROL_ROT_LEFT)
77 && (~level & CONTROL_UP) && (~level & CONTROL_DOWN) ) {
78
79 llTargetOmega(<0,0,0>, 0, 1);
81
82 llSetPos(llGetPos()); //Workaround for weird prim movement behavior
84
85 llStopAnimation(WALKANIM);
86 llStopAnimation(UPANIM);
87 llStopAnimation(DOWNANIM);
88 llStopAnimation(FLYANIM);
89 if(flying == TRUE) {
90 llStartAnimation(HOVERANIM);
91 } else {
92 llStartAnimation("stand");
93 }
94 }
95 //Turning key released
96 if((~level & edge & CONTROL_RIGHT) || (~level & edge & CONTROL_LEFT) ||
97 (~level & edge & CONTROL_ROT_RIGHT) || (~level & edge & CONTROL_ROT_LEFT)) {
98 llTargetOmega(<0,0,1>, 0, 1);
99 llTargetOmega(<0,0,-1>, 0, 1);
100 }
101 //Turn right
102 if(level & edge & (CONTROL_RIGHT|CONTROL_ROT_RIGHT)) {
103 llTargetOmega(<0,0,-1>, PI / 3.5, 1);
104 //Turn left
105 } else if(level & edge & (CONTROL_LEFT|CONTROL_ROT_LEFT)) {
106 llTargetOmega(<0,0,1>, PI / 3.5, 1);
107 }
108 //Forward
109 if(level & CONTROL_FWD) {
110 vector pos;
111 if(flying == FALSE) {
112 pos = llGetPos() + WALKSPEED*llRot2Fwd(llGetRot());
113 pos.z = zoffset + llGround(ZERO_VECTOR);
114 } else {
115 pos = llGetPos() + FLYSPEED*llRot2Fwd(llGetRot());
116 }
117 llMoveToTarget(pos, 0.1);
118 //Backwards
119 } else if(level & CONTROL_BACK) {
120 vector pos;
121 if(flying == FALSE) {
122 pos = llGetPos() - WALKSPEED*llRot2Fwd(llGetRot());
123 pos.z = zoffset + llGround(ZERO_VECTOR);
124 } else {
125 pos = llGetPos() - FLYSPEED*llRot2Fwd(llGetRot());
126 }
127 llMoveToTarget(pos, 0.1);
128 }
129 //Flying
130 if(level & CONTROL_UP) {
131 flying = TRUE;
132 llStartAnimation(UPANIM);
133 llMoveToTarget(llGetPos() + <0,0,3.5>, 0.1);
134 } else if(level & CONTROL_DOWN) {
135 llStartAnimation(DOWNANIM);
136 vector pos = llGetPos();
137 if( (pos.z - llGround(ZERO_VECTOR)) < 2.5 ) {
138 flying = FALSE;
139 }
140 llMoveToTarget(llGetPos() - <0,0,3.5>, 0.1);
141 }
142 }
143
144 //Move through solid objects
145 collision(integer det_num) {
146 if(PHANTOM == TRUE) {
150 }
151 }
152
153 touch_start(integer det_num) {
154 if(TOUCHABLE == TRUE) {
155 llSetRot(llGetRot() * llEuler2Rot(<90*DEG_TO_RAD,0,0>));
156 }
157 }
158 }
159 // END //

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