I’ll include the code but I think it’s my approach which is wrong, not my implementation.
var shape_query: PhysicsShapeQueryParameters3D = PhysicsShapeQueryParameters3D.new()
shape_query.collide_with_areas = true
shape_query.collide_with_bodies = false
shape_query.collision_mask = collision_mask
var world: World3D = get_viewport().find_world_3d()
assert(world != null, "Failed to find World3D.")
var direct_space_state: PhysicsDirectSpaceState3D = world.direct_space_state
for node: Node in editable_region.get_children():
if node is CollisionShape3D:
shape_query.shape = node.shape
shape_query.transform = node.global_transform
var collisions: Array[Dictionary] = direct_space_state.intersect_shape(shape_query, maximum_count)
assert(len(collisions) < maximum_count, "Maximum count exceeded.")
print("REGION FOUND: ", len(collisions), " ", collision_mask, " ", shape_query.shape, " ", shape_query.transform)
Some runs you’ll get nothing:
REGION FOUND: 0 32768 <BoxShape3D#-9223354138115329563> [X: (1.0, 0.0, 0.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0), O: (-15.09717, 0.200439, -13.97986)]
REGION FOUND: 0 32768 <BoxShape3D#-9223354138098561729> [X: (1.0, 0.0, 0.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0), O: (-1.153503, 4.65802, 10.23761)]
REGION FOUND: 0 32768 <BoxShape3D#-9223354138081777779> [X: (1.0, 0.0, 0.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0), O: (8.301239, 0.200439, -13.97986)]
But run the script again without changing anything and it works:
REGION FOUND: 180 32768 <BoxShape3D#-9223354138115329563> [X: (1.0, 0.0, 0.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0), O: (-15.09717, 0.200439, -13.97986)]
REGION FOUND: 592 32768 <BoxShape3D#-9223354138098561729> [X: (1.0, 0.0, 0.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0), O: (-1.153503, 4.65802, 10.23761)]
REGION FOUND: 196 32768 <BoxShape3D#-9223354138081777779> [X: (1.0, 0.0, 0.0), Y: (0.0, 1.0, 0.0), Z: (0.0, 0.0, 1.0), O: (8.301239, 0.200439, -13.97986)]