![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Anilforextra |
So, I want to detect if an object encloses other object i.e if an object is inside another object(CollisionShape in an ‘Area’ node).
One of the forums had the similiar type of discussion, where it mentioned to use encloses method from AABB class.
So, I came with this.
var OwnShapeOrigin = $CollisionShape.global_transform.origin
var OwnShapeExtents = $CollisionShape.shape.extents
var OwnShapeAABB = AABB(OwnShapeOrigin , OwnShapeExtents)
var TargetShapeOrigin = $Target/CollisionShape.global_transform.origin
var TargetShapeExtents = $Target/CollisionShape.shape.extents
var TargetShapeAABB = AABB(TargetShapeOrigin , TargetShapeExtents)
if OwnShapeAABB.encloses(TargetShapeAABB):
print("Object is inside the other object")
This is wrong.
The problems with this solution:
So,the problem is when you scale their parent nodes, they are not affected because the extents are same.I guess I have to use their scale values and not extents.
AABB class takes the origin and the scale values only:
So, when the cube collision shapes are scaled to look like rectangles and rotated,this doesn’t work.
So,I guess this is the wrong approach.
So, What is the best way to detect if an object is completely inside another?