Problems trying to limit placeable areas for items

Godot Version

4.6.1

Question

I have a system where the player can place items into the world. Since I don’t want the player to be able to place right next to a wall, or in a very small area, I’m trying to create a system that checks if where the player is placing is touching something (like a wall) and abort if it does. However, it just…doesn’t work? I’ve tried everything, checking collisions after or before an item is placed down, using raycasters even, but nothing works. Currently I have a Area3D that moves to where the item will be placed down and if the Area3D has overlapping bodies/areas, it aborts. However nothing happens? I changed the Area3D’s collision shape to be super huge even and it still didn’t work!

The code for the player placing an item is as follows, the raycast is what I use to figure out where the player is trying to place at, the Area3D is what I’ve (tried to) use to detect collisions and abort if it is colliding.

func putdown():

	if raycast.is_colliding():
		raycastcollisionpoint = raycast.get_collision_point()
		currentplayerrotation = $Pivot/Camera3D.global_rotation
		$Area3D.position = raycastcollisionpoint
		$Area3D.monitoring = true
		if $Area3D.has_overlapping_bodies():
			$Area3D.monitoring = false
			return
		else:
			emit_signal("sendraycastcollision",raycastcollisionpoint,currentplayerrotation)

maybe try checking if it collides with other areas? raycasts are tricky sometimes and don’t work

Enable Debug > Visible Collision Shapes to see what your colliders are doing at runtime.

Who calls putdown() and when? Put some print statements in there to see what pieces of code run there.

The code runs when the player character inputs a key which runs putdown(), the code running is not the problem as objects ARE being placed down. The problem is that I want the code to NOT run if the object is going to be placed too close to a wall, however currently even with my code objects are always being placed.

Nevermind, seems the problem was that the Area3D I using wasn’t “top level” and therefor moved around with the player. Works fine now!