retrace/Characters/Meldewesen/Meldewesen.gd
karl 9fd3087fdc Meldewesen runs towards player when seeing it
The NPC got some functionality which now allows it to tell the
PathNavigator where it wants to go, in addition to the default
behavior.
2019-11-11 10:49:50 +01:00

32 lines
797 B
GDScript

extends NPC
export(NodePath) var _visibility_path: NodePath
var _visibility: Area
func _ready():
Logger.set_logger_level(Logger.LOG_LEVEL_FINE)
_visibility = get_node(_visibility_path) as Area
if _visibility:
_visibility.connect("body_entered", self, "_on_body_entered_visibility")
_visibility.connect("body_exited", self, "_on_body_exited_visibility")
func _on_body_entered_visibility(body: PhysicsBody):
Logger.trace("Meldewesen seeing %s" % [body])
if body.is_in_group("Player"):
Logger.info("Seeing player!")
# TODO: Check if the Player is in an area where they shouldn't be
current_target = body.transform.origin
func _on_body_exited_visibility(body: PhysicsBody):
if body.is_in_group("Player"):
Logger.info("Stopped seeing player!")
current_target = null