From 5c212f356009b85b73ba79dac0c1579d6ef0e228 Mon Sep 17 00:00:00 2001 From: incredibleLeitman Date: Fri, 27 Dec 2019 20:50:38 +0100 Subject: [PATCH] Meldewesen following player --- Characters/Meldewesen/Meldewesen.gd | 15 +++++++++------ Characters/Util/PathNavigatorForNPC.gd | 3 +-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Characters/Meldewesen/Meldewesen.gd b/Characters/Meldewesen/Meldewesen.gd index 1861183..e456ac3 100644 --- a/Characters/Meldewesen/Meldewesen.gd +++ b/Characters/Meldewesen/Meldewesen.gd @@ -22,10 +22,14 @@ func _ready(): func _process(_delta): - # stop following player if pill level is high enough and player is not in an illegal area - if current_target and Pills.get_round_level() > _player_follow_pill_level and _playerRef.Is_in_Illegal_Area() == false: - Logger.info("player pill level ok and no illegal actions detected!") - current_target = null + if current_target: + # stop following player if pill level is high enough and player is not in an illegal area + if Pills.get_round_level() > _player_follow_pill_level and _playerRef.Is_in_Illegal_Area() == false: + Logger.info("player pill level ok and no illegal actions detected!") + current_target = null + # otherwise set new position of player + else: + current_target = _playerRef.transform.origin func _on_body_entered_visibility(body: PhysicsBody): @@ -38,9 +42,8 @@ func _on_body_entered_visibility(body: PhysicsBody): if _playerRef.Is_in_Illegal_Area(): Logger.info("player is in illegal area - following!") current_target = body.transform.origin - # If the player didn't take enough pills lately, they're suspicious -> Run towards them! - if Pills.get_round_level() <= _player_follow_pill_level: + elif Pills.get_round_level() <= _player_follow_pill_level: Logger.info("The player's pill level is too low - following!") current_target = body.transform.origin diff --git a/Characters/Util/PathNavigatorForNPC.gd b/Characters/Util/PathNavigatorForNPC.gd index 15601c7..bbdf215 100644 --- a/Characters/Util/PathNavigatorForNPC.gd +++ b/Characters/Util/PathNavigatorForNPC.gd @@ -45,8 +45,7 @@ func _process(delta): 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() + var direction_normalized: Vector3 = (current_goal - _get_body_position()).normalized() body.look_towards(direction_normalized) body.move_towards(direction_normalized * speed)