Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Aosa |
Hey. I’ve just ran into a problem while trying to make a pressure pad button in a 2D platformer.
The button should “activate” when a body enters the Area2D node and “deactivate” when no bodies are within the Area 2D node. So far I am able to get the activation part to work with: _body_entered but unable to get anything to work with _body_exited:
`extends Area2D
var isactive = false
signal on
signal off
func _on_Area2D_body_entered(body):
if body.get_name() == “Player”:
isactive = true
print(body.get_name())
print(isactive)
emit_signal(“on”)
func _on_Area2D_body_exited(body):
if body.get_name() == “Player”:
isactive = false
print(isactive)
emit_signal(“off”)`
Basically I’m wanting the “isactive” variable to swap back to false when the body leaves the Area2D. As it is now it swaps from false to true when the player enters But does not swap back to false when the player leaves.
Any suggestions for how I could write this correctly or better would be appreciated. Thanks for your time.