That's the part that's giving me headaches, the damping script. I'm trying to use llApplyRotationalImpulse to apply a counterspin over time, but it gets to the point where it seems to stop rotating, but its still applying random impulses, making it jiggle about.
Here's the damping script:
CODE
float detImpulse(float f)
{
float step = 0.2;
float i = 0.0;
integer sign = 1;
if (f < 0) {
f = f * -1;
sign = -1;
}
if (f >= step) {
i = step * sign * -1;
}
else {
i = f * -1;
}
return i;
}
default
{
state_entry()
{
llSetTimerEvent(2.0);
}
timer()
{
vector vO = llGetOmega();
vector vI = <detImpulse(vO.x), detImpulse(vO.y), detImpulse(vO.z)>;
// llSay(0, (string)vO + ", " + (string)vI);
llApplyRotationalImpulse(vI, FALSE);
}
}
and here's the follower script, if anyone wants to model it in-world. I can also five full perms copies to anyone who asks and is willing to help out. There are no problems with this script, just with the damping script above.
CODE
vector offset = <0.0, 0.0, 2.0>;
integer listen_handle;
key kAttach = NULL_KEY;
vector RestrainedWind(vector pos)
{
vector w = llWind(pos);
w.x = w.x / 5.0;
w.y = w.y / 5.0;
w.z = (w.x - w.y) / 2.5;
return w;
}
default
{
state_entry()
{
listen_handle = llListen(9, "", llGetOwner(), "");
kAttach = llGetOwner(); // default attach point
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llSetTimerEvent(0.2);
}
timer()
{
list a = llGetObjectDetails(kAttach, ([OBJECT_POS, OBJECT_ROT]));
vector avPos = llList2Vector(a,0);
vector pos = avPos;
rotation avRot = llList2Rot(a,1);
vector avOffset = (offset + RestrainedWind(avPos)) * avRot;
pos += avOffset;
llMoveToTarget(pos, 1);
}
listen(integer channel, string name, key id, string msg)
{
list lMsg = llParseString2List(msg,[" "],[]);
string cmd = llList2String(lMsg,0);
string arg = llList2String(lMsg,1);
if (llToUpper(cmd) == "ATTACH") {
if (llToUpper(arg) == "OWNER") {
kAttach = llGetOwner();
llWhisper(0, "Balloon is now attached to its owner, " + llKey2Name(kAttach));
}
}
}
on_rez(integer param)
{
llResetScript();
}
changed(integer mask)
{
if(mask & CHANGED_OWNER) {
llResetScript();
}
}
}