I'm currently developing a building system for my 2D top down game, and the last step is to check if there are any objects such as a tree or player obstructing the item from being placed. After doing some research I found out that using Physics2DShapeQueryParameters is the way to go. My only problem is I have no clue how to pass collision layers for it to check during the query using the .collision_layer method at line 3. Any insight is appreciated, thank you in advance!
var spaceState = get_world_2d().direct_space_state
var query = Physics2DShapeQueryParameters.new()
query.collision_layer = Layer1?????????? | Layer2????????????
var staticBody = get_node(itemName +"/StaticBody2D")
for shapeOwner in staticBody.get_shape_owners():
var shape = staticBody.shape_owner_get_shape(shapeOwner, 0)
shape.extents -= Vector2.ONE
query.set_shape(shape)
query.transform = staticBody.shapeOwner_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:
canBePlaced = false
return
canBePlaced = true