Hello, I'm currently making a building system for my 2D top down game. I begin by assigning a preview of the item to be at the player's mouse position and checking if the preview is within a buildable area, the issue is, I'm trying to use Physics2DShapeQueryParameters to check if there are other nodes that should prevent me from placing down the item, like a tree, rock or player already occupying that space.

My main issue is grasping how to correctly use the query. As an example let's say the item I want to place is within the collision layer WORLD and I want to check if there are any other staticBody2D or KinematicBody2D from the WORLD and PLAYER layer in the area the preview is hovering. the closest I got to a woking code was the code bellow:

Any insight is appreciated, thank you!

in the end i figured it out, I'll post the code in case someone ever has the same issue:

func getCollisionLayers(): 
	worldLayer =  0b00000001
	playerLayer = 0b00000010
	enemyLayer =  0b00001000

func checkToPlace():
	if !checkIsWithinBounds():
		return false
	var spaceState = get_world_2d().direct_space_state
	var query = Physics2DShapeQueryParameters.new()
	query.collision_layer = worldLayer | playerLayer | enemyLayer
	var staticBody = get_node(itemName +"/StaticBody2D")
	for shape_owner in staticBody.get_shape_owners():
		var shape = staticBody.shape_owner_get_shape(shape_owner, 0)
		shape.extents -= Vector2.ONE
		query.set_shape(shape)
		query.transform = staticBody.shape_owner_get_owner(0).global_transform
		query.collide_with_areas = true
		var result = spaceState.intersect_shape(query,1)
		shape.extents += Vector2.ONE
		if result.size() != 0:
			return false
	return true
a year later