Jump to content

Using llGetBoundingBox and llCastRay to adjust the position of a rezzed object


Ruthven Ravenhurst
 Share

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

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

Recommended Posts

I have an object that, when rezzed (from my inventory), floats some distance above the surface it's being rezzed on. I'm using llCastRay to find the surface height.

I got that position just fine, the problem is, the root of the object being moved isn't centered within the bounding box, and the biggest prim is a child prim. 

 

I can't seem to figure out the right formula to use the bounding box info and the root's position to determine the offset to move the object to sit on the surface

Link to comment
Share on other sites

the script is in the root, I just can't seem to figure out the right math formula to figure out the offset I should apply to the position. I've added, subtracted, divided the different vectors a bunch of different ways trying to figure out the right offset, and I can't seem to get it. i'm sure there's just one little step i'm missing, or something i have backwards somewhere. the current script I have is a mess, so don't mind that, but currently it ends up moving it some distance below the desired position. some way I had it calculated earler was close to where I wanted, but still slightly above, and I can't remember what I did to get it

 

default{    state_entry()    {        list ray = llCastRay(llGetPos(),llGetPos()+<0,0,-3>,[RC_DETECT_PHANTOM,TRUE]);        llOwnerSay(llDumpList2String(ray,"|"));        list bb = llGetBoundingBox(llGetKey());        llOwnerSay(llDumpList2String(bb,","));        vector top = llList2Vector(bb,1);        vector bottom = llList2Vector(bb,0);        vector center = (top+bottom)/2;        vector mypos = llGetPos();        vector pos = llList2Vector(ray,1)+<0,0,center.z>;        llSetPos(pos);    }}
Link to comment
Share on other sites

I think 

vector pos = llList2Vector(ray,1)+<0,0,-bottom.z>;

may be closer to what you have in mind, but this is ignoring everything about the actual shape, its rotation, and the slope of the surface, which could make this arbitrarily complicated to figure out precisely.

Incidentally, about precision, it seems llCastRay may be less precise the larger the surface it's casting towards. I'm not sure why or how that can even be true, but it's what I'm seeing (very informally).

Link to comment
Share on other sites


Qie Niangao wrote:

vector pos = llList2Vector(ray,1)+<0,0,-bottom.z>;

That was the first thing I tried, but it was putting the object under the surface.


Qie Niangao wrote:

may be closer to what you have in mind, but this is ignoring everything about the actual shape, its rotation, and the slope of the surface, which could make this arbitrarily complicated to figure out precisely.

Incidentally, about precision, it seems llCastRay may be less precise the larger the surface it's casting towards. I'm not sure why or how that can even be true, but it's what I'm seeing (very informally).

I thought about that too. I ticked the option to show bounding boxes in my viewer to make sure it was where it was supposed to be. The bounding box is where it should be (it's a mesh object), but it's not moving the object where I want

 

I did a work around by attaching a flat square mesh with a LI of 0.5 (it didn't add anything to the LI of the object), as one would add a prim shadow to something. I made that the root prim, and just used the detected surface position to set the position

Link to comment
Share on other sites


Ruthven Willenov wrote:


[ .... ]

I did a work around by attaching a flat square mesh with a LI of 0.5 (it didn't add anything to the LI of the object), as one would add a prim shadow to something. I made that the root prim, and just used the detected surface position to set the position

That may be the smartest solution in any case.  As a scripter, I find myself falling into the trap of seeing every problem as a scripting challenge, even when the best answer is something like yours: glue another prim on the sucker.  The fewer complicated parts you have, the fewer ways there are for them to go wrong.  ;)

Link to comment
Share on other sites

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