From ec020f43d3a704fdbe975940f60fcf3ca77a7f16 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 1 Nov 2017 20:58:37 +0200 Subject: [PATCH] Fixed creatures seeking towards an incorrect position when trying to eat something (causing larger creatures like threshers and coelanths to swim around the target without ever reaching it), extra check for removed entities in AITarget --- Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs | 4 ++-- .../Source/Characters/AI/EnemyAIController.cs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs index 12491c615..87f40912c 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs @@ -33,7 +33,7 @@ namespace Barotrauma { get { - if (Entity == null) + if (Entity == null || Entity.Removed) { #if DEBUG DebugConsole.ThrowError("Attempted to access a removed AITarget\n" + Environment.StackTrace); @@ -49,7 +49,7 @@ namespace Barotrauma { get { - if (Entity == null) + if (Entity == null || Entity.Removed) { #if DEBUG DebugConsole.ThrowError("Attempted to access a removed AITarget\n" + Environment.StackTrace); diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs index 5ee04843b..0d5ceab33 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs @@ -533,8 +533,7 @@ namespace Barotrauma } Vector2 attackSimPosition = Character.Submarine == null ? ConvertUnits.ToSimUnits(selectedAiTarget.WorldPosition) : selectedAiTarget.SimPosition; - - + Vector2 limbDiff = attackSimPosition - mouthPos; float limbDist = limbDiff.Length(); if (limbDist < 1.0f) @@ -577,7 +576,7 @@ namespace Barotrauma } else { - steeringManager.SteeringSeek(attackSimPosition + (mouthPos - SimPosition), 3); + steeringManager.SteeringSeek(attackSimPosition - (mouthPos - SimPosition), 3); } }