ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator Check if point is inside of Bounding Box?
person icon
drnibbert
Registered User
Quote
2026-03-16 17:19:02

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! :-)

person icon
okeoke
Registered User
Quote
2026-03-16 18:23:23

"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.

person icon
drnibbert
Registered User
Quote
2026-03-16 19:01:01

SAT? emoji icon_uh


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.

person icon
okeoke
Registered User
Quote
2026-03-17 10:34:06

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.

person icon
drnibbert
Registered User
Quote
2026-03-18 09:09:08

Thanks a lot!
"When clicked do something" only supports left click and i wanted to use the Right Mouse Button emoji icon_sad

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!


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |