Godot Version
v4.3.stable
Question
For a few weeks i’ve been working on a fun little game to learn gdscript. And I’ve usually been able to solve any problems through searching, but I’ve not been able to figure this one out.
So I’ve got a player scene I’ve defined the Characterbody2D’s parent, a Node2D, as “Player” with class_name Player
. Then in another scene which is another Node2D with an Area2D I’ve added a script which is supposed to make an E appear over the character when the Player is close. So I’ve used on_body_entered
and on_body_exited
with these functions:
func _on_area_2d_body_exited(body: Node2D) -> void:
print("exited")
if body is Player:
playerIsInRange = false
print("playerNotEntered")
eButton.visible = false
func _on_area_2d_body_entered(body: Node2D) -> void:
print("entered")
if body is Player:
playerIsInRange = true
print("playerEntered")
eButton.visible = true
I’ve added print statements to check where the code gets, and the first print statement fires, but the second doesn’t. I’ve deleted and moved the class_name Player
many times and it hasn’t worked so far. Does anyone know what could be wrong.
I can add more of the code if needed