Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How can I get a toy helium balloon to stop spinning about?

Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
02-21-2008 04:37
I'm trying to model the physics of an actual helium balloon on a string, using a follower script (using llGetObjectDetails instead of a repeated sensor sweep -- that part works great!!) and a particle chain for the string & floating effect, another script that applies a random impulse on collision which seems to work well, and a damping script to get the balloon to stop spinning and tumbling about.

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();
}
}
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
Just to make sure
02-21-2008 07:41
You know about:
llSetStatus( STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
???
It certainly will stop rotation around X and Y
There is a STATUS_ROTATE_Z constant as well
_____________________
From Studio Dora