Reputation: 11
I'm relatively new to Godot and GDScript, but am learning rapidly so I've started trying to make a 2D platformer where you can move around, and climb and slide on walls, jump from walls and stay on walls. I'm using raycast2D going from the player on the x axis to detect when the player is touching an area2D (in this case a tile that is also a staticbody2D). To test this, I wrote:
onready var raycast = get_node("RayCast2D")
func _physics_process(delta):
if raycast.collide_with_areas == true:
print("area")
The problem I'm having is the console is printing area all the time, which means that all of my tiles are area2Ds (some of them are just staticbody2D). Why are all my tiles area2Ds ?
Upvotes: 1
Views: 1524
Reputation: 58
From the RayCast2D class documentation:
bool collide_with_areas [default: false]
set_collide_with_areas(value) setter
is_collide_with_areas_enabled() getter
If true, collision with Area2Ds will be reported.
You're using collide_with_areas
as though it indicates whether the raycast is currently colliding with areas, while in truth it is a class property denoting whether the raycast should report collisions with areas at all.
Instead, you should be setting collide_with_areas
(and enabled
!) to true (either through the inspector, or via code) and then calling raycast.get_collider()
.
Upvotes: 3