[Closed] Trace place point on object below?
Hi, how would I do to detect if an object is below my selected object and then place an point helper on the object below.
Basically something like this: first check the bounding box size and position of the selected object then test if any object is directly below that area (but not below ground plane) and then create a point helper in the object center/or pivot point then place that point helper on the object that is below (not on the bounding box but on the face) else place it on ground plane, as in the example image.
Example image:
(the connecting spline is just for the screenshot)
Hope it makes some sense, thanks in advance.
That could be solved with a script controller holding one of the ray functions (intersectRay(), intersectRayEx(), intersectRayScene())
Basically, my approach would be to have on helper as the start point, and another helper that is going to be moved down. The second helper has a script controller, getting its position from the first one + a ray shooting down in Z, if there is a hit, the helper is put to the hit location, if not it is put on z=0.
You don’t need a script controller if your objects are static.
Create a ray from your node down the z axis:
r = ray myobect.pos [0,0,-1]
Intersect this ray with the ground plane:
Hitground = intersectRay GroundPlane r
Then perform intersectRay on all nodes in the scene:
Hits = intersectRayScene r
Take the maximum z result of Hits. If it’s greater than the ground one, place the Point Helper in this result, else place it in the Hitground result.
Thanks for help
This is what I did:
if $ != undefined then(
r = ray $.pos [0,0,-1];
Hits = intersectRayScene r;
point_01 = point();
if Hits.count != 0 then (
point_01.pos = Hits[1][2].pos;
)else(
point_01.pos = [$.pos.x,$.pos.y,0];
);
);
That will place a point correctly, but I get two values back from “Hits” one is the position and the second is that the “normal / or rotation / direction”?, and if so how can I use it to make the point follow the normal, cause (Hits[1][2].rotation) does not work.
#(#($Box:Box001 @ [0.000000,0.000000,0.000000], (ray [1.14108,-8.64739,25] [0,0,1])))
also is there an inspector function similar to how (show $ / or showProperties) that shows the available “values” like in this example it would show Hits[1][2].pos and Hits[1][2].something is “available”.
thanks.
<ray>.pos: Float
<ray>.position: Float --pos and position are synonyms
<ray>.dir: Point3 --unit normalized direction vector
ray.dir should do the trick.