Godot Version
4.2.2
Question
Raycast2D is not detecting collisions from Area2D
Look at the documentation. There’s a property called collide_with_areas
whose default value is false
. Have you set it to true
?
Yeah I have
I feel like we’ll need more information, because your code looks like it would work.
Have you opened a new scene and tested to see if you can even get a RayCast2D to collide at all?
This is my setup that has the raycast working:
extends RayCast2D
func _process(delta):
if Input.is_action_pressed("l_click"):
rotate(0.01)
if Input.is_action_pressed("r_click"):
rotate(-0.01)
if is_colliding():
print("IS colliding")
else:
print("NOT colliding")
I’ve only changed the collide_with_areas property to true in the RayCast2D settings. All the other properties for the other nodes are default.
Do you have “Visible Collision Shapes” enabled? With this enabled you can see the raycast, and it’ll turn red when colliding. If it turns red when colliding then the raycast is setup properly, and it’d just mean that something is wrong with your code.