Jump to content

Item creation script


JessicaGomes
 Share

You are about to reply to a thread that has been inactive for 495 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

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 by Fenix Eldritch
correction
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 495 days.

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
 Share

×
×
  • Create New...