Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | keidav |
I have a KinematicBody2D (player) and an Area2D (ladder). With the following code I get clean enter and exit events that happen as the player touches and leaves the Area2D object e.g. touch Area2D and a single “enter” prints. Move back and a single “exit” prints.
func _on_Ladder_body_entered(body):
if body.name == "Hero":
print("enter")
func _on_Ladder_body_exited(body):
if body.name == "Hero":
print("exit")
with this code things go wrong:
func _on_Ladder_body_entered(body):
if body.name == "Hero":
set_collision_layer_bit(0, false)
print("enter")
func _on_Ladder_body_exited(body):
if body.name == "Hero":
set_collision_layer_bit(0, true)
print("exit")
I get an entered event immediately followed by an exit event as soon as the player touches the Area2D. What am I doing wrong? Thanks!