Anyone have a script that will allow me to make items float on the water?
Thanks,
Rokutman
These forums are CLOSED. Please visit the new forums HERE
Script to make object float on water |
|
Rokutman Westinghouse
Registered User
Join date: 20 Oct 2006
Posts: 7
|
03-23-2009 08:55
Anyone have a script that will allow me to make items float on the water?
Thanks, Rokutman |
Cyd Woolley
Carpe Cerevisiam
Join date: 6 Jan 2007
Posts: 21
|
03-23-2009 10:24
Not sure if it's exactly what you want, but here's a script I created for an air mattress so it will float around randomly in a swimming pool topped with fake/prim water. There may be other/better approaches, but it works for me.
// Float script for a simple air mattress (or somesuch). // The containing object will float around randomly in a // level plane, regardless of altitude or underlying // terrain. The object will orient itself so that its // positive Z (up) axis points straight up. It will also // spin about its Z axis, but not around the X or Y axes. // Typically, you will want to place the containing // object within some type of enclosure. For example, // when placed inside a hollowed cylinder, this object // will bounce around inside the cylinder's hollow. float startingObjectZ; float startingGroundZ; float mass; vector velocity; vector nudge; vector rot; float interval = 1.0; integer x; integer y; integer counter = 0; vector pos; vector scale; nudgeXY() { nudge = <llFrand(0.6)-0.3, llFrand(0.6)-0.3, 0.0>; llApplyImpulse(mass*nudge, FALSE); } level() { rot = llRot2Euler(llGetRot()) * RAD_TO_DEG; x = (rot.x < -0.1 || rot.x > 0.1); y = (rot.y < -0.1 || rot.y > 0.1); if(x || y) { rot.x = 0.0; rot.y = 0.0; rot *= DEG_TO_RAD; llSetStatus(STATUS_PHYSICS, FALSE); llSetRot(llEuler2Rot(rot)); llSetStatus(STATUS_PHYSICS, TRUE); } } setHoverHeight(float z) { llGroundRepel(z, FALSE, 1.0); } default { state_entry() { // Turn off display of collision sprites. llCollisionSprite("" ![]() // Get starting Z position of float and ground. pos = llGetPos(); scale = llGetScale(); startingObjectZ = pos.z + (scale.z/2.0); startingGroundZ = llGround(ZERO_VECTOR); // Make object physical; Disable grabbing; Make object die if it wanders off. llSetStatus(STATUS_PHYSICS|STATUS_BLOCK_GRAB|STATUS_RETURN_AT_EDGE, TRUE); // Lock the float's X and Y axes to (theoretically) keep the float level. llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y, FALSE); // Set initial hover height. setHoverHeight(startingObjectZ - startingGroundZ); // Make sure the float is level, get its mass, and give it a random nudge. level(); mass = llGetMass(); nudgeXY(); // Start the timer. llSetTimerEvent(interval); } changed(integer change) { if(change & CHANGED_LINK) { // An avatar has sat or unsat; get mass and give a nudge. mass = llGetMass(); nudgeXY(); } } timer() { if(++counter % 2) { // Periodcally adjust repel height to compensate for uneven ground. float groundChange = llGround(ZERO_VECTOR) - startingGroundZ; setHoverHeight(startingObjectZ - (startingGroundZ + groundChange)); } if(counter == 10) { // Even though it shouldn't be necessary with // X & Y rotations locked, keep float level. level(); // Give the float a nudge if it's not moving much. velocity = llGetVel(); x = (velocity.x < -0.025 || velocity.x > 0.025); y = (velocity.y < -0.025 || velocity.y > 0.025); if(!x && !y) nudgeXY(); counter = 0; } } on_rez(integer param) { llResetScript(); } } |
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-23-2009 12:15
Is it a physical object, a non-physical object, or a vehicle?
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetHoverHeight http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetVehicleFlags (VEHICLE_FLAG_HOVER_*) http://www.lslwiki.net/lslwiki/wakka.php?wakka=vehicles (VEHICLE_HOVER_*) http://www.lslwiki.net/lslwiki/wakka.php?wakka=llWater http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetPos |
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
03-24-2009 06:37
Not sure if it's exactly what you want, but here's a script I created for an air mattress so it will float around randomly in a swimming pool topped with fake/prim water. There may be other/better approaches, but it works for me. .............. I was curious, so I tried out this script on an object floating on Linden water, not on fake water in a pool above the sim's water table. It doesn't work. Instead of staying on the surface, the object bobs up and down, oscillating within a half meter above and below the surface. Since my test obect is, itself, only 0.3m thick, that means it spends a good deal of its time submerged or floating stupidly in the air. I've poked at the script a bit but can't see why it should behave like that. Any ideas? |
Cyd Woolley
Carpe Cerevisiam
Join date: 6 Jan 2007
Posts: 21
|
03-24-2009 13:28
I was curious, so I tried out this script on an object floating on Linden water, not on fake water in a pool above the sim's water table. It doesn't work. Instead of staying on the surface, the object bobs up and down, oscillating within a half meter above and below the surface. Since my test obect is, itself, only 0.3m thick, that means it spends a good deal of its time submerged or floating stupidly in the air. I've poked at the script a bit but can't see why it should behave like that. Any ideas? Hello Rolig. I'm not positive what might be causing the behavior you're observing. I've only used this script on my own land. (BTW, my test object is only 0.135 "thick" in the Z dimension. Also, I have no Linden water above ground level.) Perhaps it's the fact that I don't accommodate for underlying Linden water since I'm passing FALSE for the water parameter in the call to llGroundRepel(). You might try changing the setHoverHeight() function to the following: setHoverHeight(float z) { integer water = (llWater(ZERO_VECTOR) > llGround(ZERO_VECTOR)); llGroundRepel(z, water, 1.0); } Also, I could imagine lag might cause the behavior you're seeing since the script is timer based. I don't have much lag on my land. EDIT: If you'd like to see my test float, come to Ifrit<113, 125, 47>. |
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
03-24-2009 14:19
Thanks. I'll give it a try when I can get in world this evening. Mostly, I was curious to see how it worked, but I do have a couple of floating objects in a pond that might look more realistic if they drifted gently. Lag isn't bad on the sim, so the timer probably isn't the problem.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
03-24-2009 16:24
LOL.... Well, that was interesting.... I made the change you suggested and my test prim ascended rapidly. I had to grab quickly before it escaped. Thanks anyway. I'll set this one aside and play with it another day.
![]() |
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-24-2009 18:57
It would be the call to llApplyImpulse() that is causing the object to bounce up and down.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
03-25-2009 07:50
It would be the call to llApplyImpulse() that is causing the object to bounce up and down. How can that be true? The velocity vector being used in that call has no Z component. |
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-25-2009 09:49
How can that be true? The velocity vector being used in that call has no Z component. Oops! Right you are. I misread that part. Hmm. Possibly it has to do with the ground repel. It is set to move the center of the object up to where the TOP of the object is originally. I'd probably try changing that. Play with the damping coefficient too. Is it possible this object is colliding horizontally with other objects, causing a deflection in the z direction? http://jira.secondlife.com/browse/SVC-3783 ![]() |
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
03-25-2009 10:09
OK, I think...... I haven't had any reason to look at the llGroundRepel function before. The way this script is written, it manages the Z component with
CODE
Since my experiments with this script have all been with a test object floating on Linden water at the water table, it shouldn't make any difference whether the second parameter is TRUE or FALSE, right? It's never over anything but water. I can certainly muck around with the third variable to change the damping response -- I'll try that when I can get in world this evening -- but that still begs the question of why the object should ever wander in the Z direction at all. Where's the Z force coming from? Why is it even necessary to damp vertical oscillations? What causes them? (You can probably tell that I have never built a vehicle. I'm just using this script as an excuse to learn something. ![]() Edit: No, it's not colliding with anything. Just floating around in the middle of a pond. |
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-25-2009 10:21
Is an avatar stepping or jumping onto it, and off again?
If it is over Linden water, you might want to change the parameter to TRUE, and go to a constant z-value rather than worrying about the height of the ground. You might also play with switching to a function like llSetHoverHeight() rather than llGroundRepel(). I'm not sure it'll be your answer, but it's worth a try. http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetHoverHeight Oh. Something else just occurred to me. I wonder if the object is running out of energy, and having trouble holding itself up. How massive is it? You might temporarily put in a llOwnerSay() that reports the results of llGetEnergy() to see if that's an issue. http://www.lslwiki.net/lslwiki/wakka.php?wakka=energy |
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
03-25-2009 10:37
No, I haven't had a chance to jump on it yet. So far, I've just been trying to get it to behave itself without my interference. I can see that would be a consideration once I get to that point, though. Good observation. I suspect that's why the scripter wrote this code with llGroundRepel instead of llSetHoverHeight, though. Once I DO jump on it and add a Z force, I can't assume a constant z any more.
It still puzzles me why there's a Z force now. I'll follow your suggestion and think about energy some more. I guess I assumed that there was something equivalent to a bouyant force built into llGroundRepel so that the object doesn't sink into the ground/water surface. That is, it shouldn't ever run out of energy unless you do something deliberate to lift it above the water table or land surface. Are there random pseudo-forces at work in SL due to server performance issues, maybe? |
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
03-25-2009 11:21
Ah! Wait! I think I see. (/me starts talking to herself....)
The way this script is written, it sets hover height initially relative to the ground surface. So long as the second parameter in llGroundRepel is set to FALSE, the script keeps adjusting Z relative to the bottom of the pond, not relative to the water surface. Since the bottom is irregular, moving my test object horizontally implies also moving it vertically. Therefore, your suggestion about changing that parameter to TRUE or using llSetHoverHeight instead should do the trick. I wish I could get in world now to try it out..... ![]() |
Cyd Woolley
Carpe Cerevisiam
Join date: 6 Jan 2007
Posts: 21
|
03-25-2009 12:13
Ah! Wait! I think I see. (/me starts talking to herself....) ...changing that parameter to TRUE or using llSetHoverHeight instead should do the trick. I wish I could get in world now to try it out..... ![]() Yes, the new setHoverHeight() function I provided in my previous post (#5) should set the water parameter to TRUE when Linden water is nearer to the bottom of the containing object than is ground, and FALSE otherwise. |
Cyd Woolley
Carpe Cerevisiam
Join date: 6 Jan 2007
Posts: 21
|
03-25-2009 14:40
...You might also play with switching to a function like llSetHoverHeight() rather than llGroundRepel()... Hi Hewee. I originally thought of using llSetHoverHeight() instead of llGroundRepel(). However, llSetHoverHeight() does not support hovering more than 64 meters above the ground (per the SL Wiki). Since I wanted my float to work at higher altitudes, I had to go with llGroundRepel() instead. |
Alisha Matova
Too Old; Do Not Want!
Join date: 8 Mar 2007
Posts: 583
|
03-25-2009 15:34
Actually this makes a neat raft of sorts.
replace: llGroundRepel(z, FALSE, 1.0); with this: llGroundRepel(.2, TRUE, 1.0); I'm standing on it now, drifting across the water. |
Rokutman Westinghouse
Registered User
Join date: 20 Oct 2006
Posts: 7
|
03-28-2009 14:12
Thanks all for your working on this.
|