-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathanimeshao.lsl
105 lines (92 loc) · 3.29 KB
/
animeshao.lsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// Animesh AO
//
// Manages movement animations for an avatar
//
// TEST ONLY
//
// Animats
// 2019
//
string IDLE_ANIM = "CCBirdGirlStand01.2"; // idle or chatting
string STAND_ANIM = "bp hands behind back"; // just when stopped
string WALK_ANIM = "Female Walk 1";
string TURN_ANIM = "RD Walk In Place"; // when turning
float POLL_TIME = 0.5;
float IDLE_TICKS = 10; // 5 secs to shutdown
float SPEED_WALK = 0.1; // faster than this, walking
float ROTRATE_TURN = 0.3; // medium speed turn
// ***MORE*** run, etc.
// Globals
string gStandAnim = STAND_ANIM; // base stand animation
string gCurrentAnim = ""; // no current animation
integer gMoving;
integer gIdleTicks; // not moving, turn off
stop_anims()
{ list anims = llGetObjectAnimationNames();
integer i;
for (i=0; i < llGetListLength(anims); i++)
{ string s = llList2String(anims,i);
llOwnerSay("Stopping " + s);
llStopObjectAnimation(s);
}
}
start_anim(string anim)
{ if (gCurrentAnim == anim) { return; } // no change
stop_anims(); // stop old anims
llStartObjectAnimation(anim); // start new anim
llOwnerSay("Start animation " + anim); // change animation
gCurrentAnim = anim; // current anim
}
update_anim() // called periodically and when movement starts
{
float speed = llVecMag(llGetVel()); // moving how fast?
float rotspeed = llVecMag(llGetOmega());// rotating how fast
if (speed < SPEED_WALK) // just stand or walk for now
{ if (rotspeed > ROTRATE_TURN)
{ start_anim(TURN_ANIM);
gIdleTicks = 0; // not idel
}
else
{ start_anim(gStandAnim);
if (!gMoving) // if not moving, still might be turning
{ gIdleTicks++;
if (gIdleTicks > IDLE_TICKS) // idle, ingnore until awakened
{ llSetTimerEvent(0.0); } // put AO to sleep to reduce load
}
}
} else {
gIdleTicks = 0;
start_anim(WALK_ANIM);
}
}
default
{
state_entry()
{
gMoving = FALSE;
gIdleTicks = 0;
}
on_rez(integer param)
{ llResetScript(); }
timer()
{ update_anim(); }
moving_start() // run timer only when moving
{ llSetTimerEvent(POLL_TIME);
gMoving = TRUE;
update_anim(); // update immediately
gIdleTicks = 0;
}
moving_end()
{
gMoving = FALSE;
gIdleTicks = 0; // begin shutdown timing
}
link_message(integer source, integer num, string str, key id)
{
llSetTimerEvent(POLL_TIME); // wake up
gIdleTicks = 0; // stay awake long enough to do whatever asked to do
if (num == 1) // change stand animation
{ gStandAnim = str; } // use new stand animation
}
}