|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
GodotNoob69 |
I have a piece of code that needs the “if is_colliding” line. but I get an error saying it’s not declared. how do i fix this?. I have seen this exact question asked, BUT i did not understand the answer in the slightest so i would appreciate if someone very much dummed down the answer for me. Thanks.
edit: So sorry, I forgot to add the code. Please let me know if there is more detail needed I don’t know how to set out a question
extends Area2D
func _on_Area2D_body_entered(body):
if is_colliding():
queue_free()
There are only a couple of ways to make working code, but a thousand ways to make bugs. To identify your bug, we need more than you telling us: “I have a bug”.
Show us your code … otherwise we can’t see what is going wrong.
I don’t see is_colliding() documented in Area2D. body_entered is called on collision anyway so it wouldn’t be necessary, especially if you’re calling queue_free() afterwards.
|
|
|
|
Reply From: |
wombatstampede |
That would be difficult if you don’t let us know WHAT this peace of code contains and which purpose it serves.
Anyway, the docs tell me that is_colliding() is a method of the RayCast or RayCast2D nodes:
So you’d need to understand what a RayCast is (the docs have a section for that as well) and then add such a RayCast to your scene tree where it is required.
Then get that node and use is_colliding. If that script is proposed to be added to such a RayCast node then you won’t need to get that node as it is implicitly using “self” (my guess).
Ok, there is no is_colliding() for Area2D. May be this code is from an older tutorial, maybe for Godot 2.x?
Anyway let’s have a look at Area2D:
Area2D — Godot Engine (latest) documentation in English
When I look at the code then I see no point in checking is_colliding()
because the signal on_body_entered
has already been triggered. But if you want to check anyway then I’d use if !get_overlapping_bodies().empty():
to check if the Area is colliding with bodies or if !get_overlapping_areas().empty():
to check if it is colliding with other areas.
wombatstampede | 2019-05-07 13:15