Untested, but something like this:
In the Player
script
In the Fuel Station
script
func on_Gasbody_entered(body):
if "fuel_fill" in body:
body.fuel_fill = true
func on_Gasbody_exited(body):
if "fuel_fill" in body:
body.fuel_fill = false
Be sure to wire both the entered
and exited
signals on the Area2D
, and connect them to the above 2 methods respectively.
With that, when something with a fuel_fill
property enters the Area2D
, it'll set the body's fuel_fill
property to true. In turn, that'll cause the fillFuel()
method to be called from the Player's _process()
function.
And, when something with a fuel_fill
property exits the Area2D
, it'll set the body's fuel_fill
property to false. That'll cause the fillFuel()
fuction to stop being called in the Player.
You may need to season to taste, but that should get you close to something that works.