Area2D in 3D world question

Godot Version

4.3

Question

how to make screen space area2d get obscured behind walls that’s in world space?

as you can see from the image, the enemy on the left is partially obscured by the left wall, but it’s area2d collider is still fully visible. i want the collider to also be hidden behind wall just like the 3d model

also i need the area2d blue crosshair (also screen space) to be able to damage every enemy that’s inside of it, not just at the center. so i don’t think raycast is gonna work.

here’s the enemies area2d code, in case it’s needed.

extends Area2D

@onready var enemy = get_parent()
@onready var camera = $"../../../Camera3D"
@onready var hitboxShape = $CollisionShape2D

var base_extents = Vector2(1, 1)

func _ready():
	hitboxShape.shape = RectangleShape2D.new()

func _process(delta):
	AdjustHitboxSize()
	var screen_pos = camera.unproject_position(enemy.global_transform.origin)
	global_position = screen_pos  

func AdjustHitboxSize() -> void:
	var rect_shape = hitboxShape.shape as RectangleShape2D
	if not rect_shape:
		return  
	
	var distance = (enemy.global_transform.origin - camera.global_transform.origin).length()
	var scale_factor = camera.fov / distance
	
	rect_shape.extents = base_extents * scale_factor
	hitboxShape.force_update_transform()

You don’t. Physics 2D and Physics 3D are two different systems which don’t interact with each other.
If you are in 3D, use only 3D objects.

For interacting screen position with 3D objects, you can cast rays.

For interaction within the 3D Cone, you could perhaps use a ConvexPolygonShape3D, but I’m not sure, if that approach has problems.

2 Likes