Many ways of doing it. One I can think of quickly is that shapes have collision methods that you can work with if you get the shapes involved.
https://docs.godotengine.org/en/3.2/classes/class_shape2d.html#class-shape2d
An example would look like this:
extends Node2D
var actors = []
func make_actor_at(p_position):
var s = Sprite.new()
var k = KinematicBody2D.new()
var r = RectangleShape2D.new()
var tex = preload("res://icon.png")
r.extents = tex.get_size() / 2.0
s.texture = tex
k.add_child(s)
k.create_shape_owner(k)
k.shape_owner_add_shape(0, r)
var a1_xform = Transform2D(0.0, p_position) * k.shape_owner_get_transform(0)
var collisions = 0
for actor in actors:
var shape = actor.shape_owner_get_shape(0, 0)
var s_xform = actor.shape_owner_get_transform(0)
print(s_xform)
var a2_xform = actor.global_transform * s_xform
print(shape)
if(r.collide(a1_xform, shape, a2_xform)):
print("Collides with: ", actor)
collisions += 1
if(collisions == 0):
actors.append(k)
add_child(k)
k.global_position = p_position
else:
k.free()
func _input(e):
if(e is InputEventMouseButton and e.pressed and e.button_index == BUTTON_LEFT):
make_actor_at(get_global_mouse_position())
Another alternative is to get the direct space state, and construct queries. This can be accessed on any Node2D.
get_world_2d().direct_space_state
The methods and their requirements can be found here:
https://docs.godotengine.org/en/3.2/classes/class_physics2ddirectspacestate.html?highlight=cast_motion
And a more advanced option is to work directly with the Physics2DServer. Creating the bodies and shapes, and handling things using their RIDs. (Though it's more for situations when you want performance.)
https://docs.godotengine.org/en/stable/classes/class_physics2dserver.html
There are also other creative things you could do if you bring the actor in invisibly, and use other typical techniques to check collisions, resolve them, and then show the actor.