JessicaGomes Posted November 19, 2022 Share Posted November 19, 2022 I want to make the item I wore disappear when it detects water, but what is the script command to detect water? Link to comment Share on other sites More sharing options...
Fenix Eldritch Posted November 19, 2022 Share Posted November 19, 2022 (edited) By detect, I presume you mean something to the effect of whether your avatar is currently in or under the water. The only command that deals with water is llWater. It returns a float which is the height of the water level at the object's current position plus an offset. Since the object is an attachment, its position is the same as our avatar's position, so we can just specify ZERO_VECTOR as the offset. To tell if your avatar is "in" the water, you would want to compare the value returned by llWater(ZERO_VECTOR) with the Z component of your avatar's current position vector returned by llGetPos. (you can access the individual X Y or Z components of a vector by appending .x .y or .z respectively when referencing the variable). If your vertical position is less than or equal to the water level, then you can conclude that you are in the water. Note that the position returned by llGetPos relates to the "center" of the avatar which is about waist-high. So if you want to get the coordinates of say, your feet, you would need to compensate for that. One way is to subtract half the avatar's height from its current position. Something like this: default { touch_start(integer total_number) { vector av = llGetAgentSize(llGetOwner()); //get (approximate) size of avatar vector p = llGetPos()-<0,0,(av.z/2)>; //get our position & subtract half avatar height from z component. (this will give the position of our feet) float w = llWater(ZERO_VECTOR); //get water height at our position w = p.z-w; //subtract water height (w) from our feet height (p.z) if (w <= 0) { llOwnerSay("you are in water"); } else { llOwnerSay("you are "+(string)w+"meters above the water"); } } } To have your attachment react to the avatar contacting the water, it would need to be running that check on a repeating timer. Perhaps with an interval of once every second or greater. Note that this is only viable for "Linden Water"... it won't work for user made prims that are meant to look like water. Edited November 19, 2022 by Fenix Eldritch correction 1 Link to comment Share on other sites More sharing options...
JessicaGomes Posted November 20, 2022 Author Share Posted November 20, 2022 thank you for your kind reply 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now