diff --git a/Characters/Meldewesen/Meldewesen.gd b/Characters/Meldewesen/Meldewesen.gd index 0fc790f..469d401 100644 --- a/Characters/Meldewesen/Meldewesen.gd +++ b/Characters/Meldewesen/Meldewesen.gd @@ -15,18 +15,17 @@ func _ready(): _visibility.connect("body_exited", self, "_on_body_exited_visibility") -func _on_body_entered_visibility(body: Node): +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 - # TODO: Follow the Player + current_target = body.transform.origin -func _on_body_exited_visibility(body: Node): +func _on_body_exited_visibility(body: PhysicsBody): if body.is_in_group("Player"): - print("Stopped seeing player!") Logger.info("Stopped seeing player!") - # TODO: Stop following the Player + current_target = null diff --git a/Characters/NPC.gd b/Characters/NPC.gd index 8f61c63..ed3b568 100644 --- a/Characters/NPC.gd +++ b/Characters/NPC.gd @@ -1,2 +1,13 @@ extends KinematicBody class_name NPC + + +var current_target = null + + +func set_position(position: Vector3): + transform.origin = position + + +func move_towards(direction_times_speed: Vector3): + move_and_slide(direction_times_speed) \ No newline at end of file diff --git a/Characters/Util/PathNavigatorForNPC.gd b/Characters/Util/PathNavigatorForNPC.gd index 24fd7dd..4a4fa94 100644 --- a/Characters/Util/PathNavigatorForNPC.gd +++ b/Characters/Util/PathNavigatorForNPC.gd @@ -34,20 +34,21 @@ func _restart_navigation(): body = get_node(body_nodepath) as KinematicBody # Initialize the position - body.transform.origin = curve.get_point_position(0) + body.set_position(curve.get_point_position(0)) # Get the first goal _get_new_navigation() func _process(delta): - var current_goal = _get_current_goal() + # Use either the NPC's current target or the paths next goal + var current_goal = body.current_target if body.current_target else _get_current_goal() # Move towards the current goal var direction: Vector3 = (current_goal - _get_body_position()) var direction_normalized: Vector3 = direction.normalized() - body.move_and_slide(direction_normalized * speed) + body.move_towards(direction_normalized * speed) # Look towards that goal as well # Avoid look_at if we're already (almost) there, since that'd be an invalid look direction