Ok, so for anyone interested, this is what I came up with.
As a test, I created a new project. I then created a new Node3D called ‘World’. Camera and light optional.
As a child of ‘World’, I created a StaticBody3D. I renamed it to (1,1,1). I added a CollisionShape3D object to it as a child. I made the collision object a BoxShape and set the size to 8x8x8 and the position to 4x4x4. I positioned the static body at (0,0,0) in the scene.
I then duplicated the static body 3 more times and renamed them to (-1,1,1), (-1,1,-1) and (1,1,-1) and positioned them at (-8,0,0), (-8,0,-8) and (0,0,-8) respectively in the scene.
I attached a new script to the ‘World’ node with the following:
func _ready() -> void:
print(get_colliders_at_many_points([Vector3(0,0,0)]))
func get_colliders_at_many_points(points: Array, collision_mask := 1):
var space_state = get_world_3d().direct_space_state
var shape := BoxShape3D.new()
shape.size = Vector3(0.1, 0.1, 0.1)
var query := PhysicsShapeQueryParameters3D.new()
query.shape = shape
query.collision_mask = collision_mask
var results := []
for point in points:
query.transform = Transform3D.IDENTITY.translated(point)
# I set 8 as the max number of collision objects to query
var intersections = space_state.intersect_shape(query, 8)
for result in intersections:
results.append({
"point": point,
"name": str(result.collider.name),
"local_position": (result.collider.global_transform.origin - point).abs()
})
return(results)
This can check an array of coordinates passed into it however I ended up just querying individual Vector3’s as needed.
If you would like to see an example of the final usage, check out /watch?v=4Iue6Yp3D2Q on Youtube. The video is an older version of the project but using the new method, it’s functionally the same.
Enjoy!