Jump to content

Calculating the height of an object above the ground when that 'ground' is say a sky platform


GloriaGlitter
 Share

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

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

Recommended Posts

If I creat a new object, then it is positioned a ground level, even if on a platform say 500 mtrs up.  If I edit the object and raise it up some distance and then take it back into inventory, when I rez it again, it will be the same height above the ground.

What I would like to do is to find out the height of the platform so that I can adjust the position of my object so that it is back on the ground again e.g. llSetPos(llGetPos()-<0,0,HeightAboveGround>).  Is the height of a platform available as a variable or as a calculated value so that I can calculate vector 'HeightAboveGround'?

 

Thanks

Link to comment
Share on other sites

1 hour ago, GloriaGlitter said:

If I creat a new object, then it is positioned a ground level, even if on a platform say 500 mtrs up.  If I edit the object and raise it up some distance and then take it back into inventory, when I rez it again, it will be the same height above the ground.

Can you demonstrate this? I've never seen this kind of behavior (and couldn't replicate it), the object/linkset is generally rezzed so that the bottom of its bounding box is against whatever surface it was rezzed on, and that position is calculated by the viewer.

Link to comment
Share on other sites

I think your use of the term "ground" is confusing us. Ground is specifically thought of as the land/terrain of a region. Whereas sky platforms are just another kind of object. And as Wiulfie explains, any time you manually rez an object, it will be positioned such that its bounding box is on top of whatever surface you tried to rez on - whether that is the ground or another object.

So from the title, are you saying you want to have an object maintain a recorded height above any surface, be it the ground or a platform? If so, you first need to measure the distance between the object after you're positioned it and the closest surface below it. You can use llCastRay to get the position of the surface and then subtract that from the object's current position. Then in an on_rez event, you could apply that offset.

Something like this:

float heightOffset = 0.0;

default
{
    touch_start(integer num_touches)
    {
        vector startPos = llGetPos();           //initial position of object at rest
        vector endPos = startPos - <0,0,100>;   //arbritrary scan distance of 100m below
        list results = llCastRay(startPos, endPos, [RC_REJECT_TYPES, RC_REJECT_AGENTS, RC_MAX_HITS, 1] );
        if(llList2Integer(results, -1) >= 0)
        {
            vector rayHit = llList2Vector(results, 1); //get position of ray impact
            heightOffset = startPos.z - rayHit.z;      //get distance between our position and the surface position
        }
        if(heightOffset >= startPos.z)
        {
            heightOffset = 0;   //failsafe: don't allow offset to be higher than current altitude
        }
        
        llOwnerSay("Measured height above nearest surface below me: "+(string)heightOffset);
    }
    
    on_rez(integer parm)
    {   
        //Need to compensate for the altitude of the freshly rezzed object
        //Get the bounding box z size and subtract half of it from the offset
        list bb = llGetBoundingBox(llGetKey());
        vector size = llList2Vector(bb, 1) - llList2Vector(bb, 0);
        
        llOwnerSay("Repositioning...");
        llSetPos(llGetPos()+<0,0,heightOffset-(size.z*0.5)>);
    }
}

 

Edit: I realized I had a couple flaws in my example. Just before you actually do the repositioning, you need to account for the position of the freshly rezzed object. Otherwise the final position will be higher than intended by half of the object's overall vertical size. We can compensate for this by getting the object bounding box and subtracting half of the z component from the offset.

Edited by Fenix Eldritch
corrections, additional info
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 569 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...