Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Floating wood

Virtual Bacon
Registered User
Join date: 23 Sep 2005
Posts: 1
08-28-2006 22:06
Anyone give any direction on writing a script to make something float on top of the water like a piece of wood? The goal is to have it move in the water with the waves.
Thanks!
Sawdust Fossil
Registered User
Join date: 3 Aug 2006
Posts: 28
08-29-2006 05:28
I just happened to have completed a series of experiments on getting an object to float:
(If anyone else has tried something, I, too, would like to hear it.)

I tried 5 ways to script a physical object to float in water:
1. Simply giving the object the property of "llGroundRepel"
2. Simply giving the object the property of "llHoverHeight"
The next three methods all used a frequently called TimerEvent which checked the object's position versus the water level (using llWater):
3. used llSetForce to move the object up if below water, stopped applying force if above water
4. same thing as 3, but used llMoveToTarget
5. same thing as 3, but used llSetBuoyancy

The best result of all was using the llGroundRepel function. Stick this code in a *physical* object and it behaves normally on land, but floats (half in and half out) in the water:
CODE
    state_entry()
{
llGroundRepel(0.1,TRUE,1);
}
That is all you really need, but there are two drawbacks. One, the object does not bob up-and-down upon initially falling into water. It, somewhat unrealistically, instantly stops at its prescribed height in the water (but it is still better than the other 4 methods). Two, an object floating in the water using this method sees no friction...so, any momentum in the X or Y direction means the object glides along indefinitely! I found a cheap fix by adding a timer event to stop the object's momentum every so often:
CODE
default
{
state_entry()
{
llGroundRepel(0.1,TRUE,1);
llSetTimerEvent(30);
}

timer()
{
llApplyImpulse(-llGetMass()*llGetVel(),FALSE);
}
}
There may be a better/more elegant way to stop the object. Please let me know if anyone has any ideas.

--

As for the other methods of floating:
llHoverHeight worked almost as well as llGroundRepel, except that when the object was thrown over a cliff into a lake, the object slowly fell into the water in a weird, hovering way...it looked most unnatural. llGroundRepel did not have this problem.

the other 3 methods (3, 4,and 5, above) all had the same problem:
The object ended up endlessly bouncing far below the water's surface and then flying high above the water and then back down. It was comical! :) The three different methods behaved slightly differently, but I forget the details.

This ended up being a long post! Anyway, good luck!
Tere Karuna
Registered User
Join date: 4 Jul 2004
Posts: 159
08-30-2006 20:10
Using your method; does it complicate situation if a AV is sitting on the object?
_____________________
"ooohhhh we didnt know what we had till it was gone;
they paved secondlife and put up a shoping mall,
oooooo, ba ba ba....."
Sawdust Fossil
Registered User
Join date: 3 Aug 2006
Posts: 28
09-01-2006 09:34
Using llGroundRepel, sitting on the object has no effect.

If you *wanted* there to be an effect, you could pr'y program the object to "sink" lower in the water if it is being sat upon (by altering the appropriate value in llGroundRepel).

For a fun ride, create a large physical sphere and give it the llGroundRepel for floating in water. Then sit on the sphere and toss it (with you sitting on it!) into some water. You will get a great rolling ride as the sphere continues to spin with residual motion from being tossed into the water. Switch to mouseview for a stomach-churning view! :)