Difference between revisions of "LlGround"

From Second Life Wiki
Jump to navigation Jump to search
(buggy (flawed logic) & didn't compile)
Line 10: Line 10:
|constants
|constants
|examples=<pre>
|examples=<pre>
// by Konigmann Lippmann
// by Konigmann Lippmann & Strife Onizuka
FindGroundOrWater()
FindGroundOrWater()
{
{
     float fGroundHeight = llGround( <0,0,0> );
     float fHeight = llGround( ZERO_VECTOR );
     float fWaterLevel = llWater( <0,0,0> );
     float fWaterLevel = llWater( ZERO_VECTOR );
     integer iRepeats = 0;
     if( fHeight < fWaterLevel )
if( fGroundHeight < fWaterLevel )
        fHeight = fWaterLevel;
fGroundHeight = fWaterLevel;
     vector vTarget = llGetPos();
     vector vOldPosition = llGetPos();
 
    vector vNewPosition = vOldPosition;
     //llSetPos can only move 10m at a time.
     vNewPosition.z = fGroundHeight;
     integer iCounter = 1 + llAbs((integer)(vTarget.z - fHeight) / 10);
     while( (llAbs((integer)(vOldPosition.z - vNewPosition.z)) > 2.0 ) && (fGroundHeight>iRepeats) )
    vTarget.z = fHeight;
     {
     do
         llSetPos( vNewPosition );
         llSetPos( vTarget );
        vOldPosition = llGetPos();
    while( --iCounter );
    iRepeats++; //iRepeats is used as a safety valve to make sure that this routine doesn't run forever.
    }
}
}


Line 32: Line 30:
{
{
     touch_start(integer total_number)
     touch_start(integer total_number)
    {
         FindGroundOrWater();
         FindGroundOrWater();
    }
}
}
</pre>
</pre>

Revision as of 22:03, 2 September 2007

Summary

Function: float llGround( vector offset );
0.0 Forced Delay
10.0 Energy

Returns a float that is the ground height below the object position + offset

• vector offset

The requested position needs to be in the same sim, only the X & Y of the offset are important.

Examples

// by Konigmann Lippmann & Strife Onizuka
FindGroundOrWater()
{
    float fHeight = llGround( ZERO_VECTOR );
    float fWaterLevel = llWater( ZERO_VECTOR );
    if( fHeight < fWaterLevel )
        fHeight = fWaterLevel;
    vector vTarget = llGetPos();

    //llSetPos can only move 10m at a time.
    integer iCounter = 1 + llAbs((integer)(vTarget.z - fHeight) / 10);
    vTarget.z = fHeight;
    do
        llSetPos( vTarget );
    while( --iCounter );
}

default
{
    touch_start(integer total_number)
    {
        FindGroundOrWater();
    }
}

See Also

Functions

•  llGroundContour Gets the ground contour
•  llGroundNormal Gets the ground normal
•  llGroundSlope Gets the ground slope

Deep Notes

Signature

function float llGround( vector offset );