Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hello :-) is there a way to get access to the Bounding box of a 3d object with scripting - and secondly to check (cost-efficiently) if a 3d-point is inside this bounding box? ("LineCollideWithBoundingBox" didn't do what i wanted...) I could find neither in the script-documentation.... Basically just what the pre-built "On Proximity do something"-Function does, but with scripting :-) Thanks a lot! :-) |
||||
|
"On proximity" is a simple distance check, or you can say point to sphere. You can get position of both nodes and calculate distance between them, if it is less than threshold - fire an event. If you want to optimize that - use squared distance without calculating sqrt. Point in the box is a bit harder. In case the box doesn't rotate it is simple enough - https://math.stackexchange.com/questions/1472049/check-if-a-point-is-inside-a-rectangular-shaped-area-3d If the box rotates the only way I know is using SAT. If it shouldn't be super precise, I suggest just using simple distance check. |
||||
|
SAT? But "On Promimity" does have this Box-Option that checks if the Origin of another object entered it's hitbox - i think this also works on rotating objects? My problem is the following: i have a bunch of clones of an object and want to "find out" wich one i have clicked on. I use the Raycast between camera and "get 3d from 2d" - but it also detects objects that are BEHIND the one i've clicked on. WIth "Collision with world" i can identify a point on the exact one i've clicked, but if i use a simple distance-check on the clones (iterating and comparing wich one is closest to the clicked 3d-point) i get wrong results if the origin of another object is actually closer then the one i've clicked on. |
||||
|
Why don't you use built-in "When Clicked do something" behavior? https://www.ambiera.com/coppercube/doc/cnt_behaviors.html You can raycast, but it's sort of pricy performance-wise. If you have a lot of objects I would suggest not do that. But if you decide to do that - you can sort all the nodes you need to check by the distance to player, then raycast to all of them starting from the closest one. As soon as collision is found - stop raycasting. That way the ones that are behind the node you interact with will not be checked. |
||||
|
Thanks a lot! "When clicked do something" only supports left click and i wanted to use the Right Mouse Button But having the detection-ray moving forward until detecting the first (and only one) collision is perfect! :-) Maybe i can incementally shorten the interval in wich the raycast moves forward until it collides with only one node, to keep performance reasonable :-) Thanks a lot! |
||||
|
|