diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AICharacter.cs b/Barotrauma/BarotraumaShared/Source/Characters/AICharacter.cs index c12fa49e0..4ccc10788 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AICharacter.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AICharacter.cs @@ -1,10 +1,17 @@ using Microsoft.Xna.Framework; -using System; namespace Barotrauma { partial class AICharacter : Character { + //characters that are further than this from the camera (and all clients) + //have all their limb physics bodies disabled + const float EnableSimplePhysicsDist = 10000.0f; + const float DisableSimplePhysicsDist = EnableSimplePhysicsDist * 0.9f; + + const float EnableSimplePhysicsDistSqr = EnableSimplePhysicsDist * EnableSimplePhysicsDist; + const float DisableSimplePhysicsDistSqr = DisableSimplePhysicsDist * DisableSimplePhysicsDist; + private AIController aiController; public override AIController AIController @@ -32,17 +39,34 @@ namespace Barotrauma if (!IsRemotePlayer) { - float dist = Vector2.DistanceSquared(cam.WorldViewCenter, WorldPosition); - if (dist > 8000.0f * 8000.0f) + float characterDist = Vector2.DistanceSquared(cam.WorldViewCenter, WorldPosition); + if (GameMain.Server != null) + { + //get the distance from the closest player to this character + foreach (Character c in CharacterList) + { + if (c != this && (c.IsRemotePlayer || c == GameMain.Server.Character)) + { + float dist = Vector2.DistanceSquared(c.WorldPosition, WorldPosition); + if (dist < characterDist) + { + characterDist = dist; + if (characterDist < DisableSimplePhysicsDistSqr) break; + } + } + } + } + + if (characterDist > EnableSimplePhysicsDistSqr) { AnimController.SimplePhysicsEnabled = true; } - else if (dist < 7000.0f * 7000.0f) + else if (characterDist < DisableSimplePhysicsDistSqr) { AnimController.SimplePhysicsEnabled = false; } } - + if (IsDead || Health <= 0.0f || IsUnconscious || Stun > 0.0f) return; if (Controlled == this || !aiController.Enabled) return;