I have this code
extends Node2D
@export_flags_2d_physics var ray_mask = 0
@onready var space_state := get_world_2d().direct_space_state
@onready var ray_params: PhysicsRayQueryParameters2D = PhysicsRayQueryParameters2D.create(
Vector2.ZERO,
Vector2.ZERO,
ray_mask
)
var input_vector := Vector2.ZERO
func _ready() -> void:
ray_params.collide_with_areas = true
func get_input_vector() -> Vector2:
return Input.get_vector("move_left", "move_right", "move_up", "move_down")
func get_ray_collision(direction: Vector2, distance: float) -> Dictionary:
ray_params.from = global_position
ray_params.to = ray_params.from + direction * distance
return space_state.intersect_ray(ray_params)
func handle() -> void:
var collision = get_ray_collision(get_input_vector(), 100)
if not collision.is_empty():
print("Collision with: ", collision.collider.get_name())
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
input_vector = get_input_vector()
queue_redraw()
pass
func _draw() -> void:
draw_line(Vector2.ZERO, Vector2.ZERO + input_vector * 100, Color.GREEN, 8.0)
And a scene with an area2d and a collisionshape2d (see attached 1). Collisions layers are set to 1,2,3 and masks to 1,2,3. The script that calls the ray cast searchs for layer 3 (see second attached image)
What am I doing wrong?