From 2fe8139ffd235aa3996bae6a3af1af62ce23e204 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 8 Apr 2019 12:06:53 +0300 Subject: [PATCH] (b651e55f4) Don't quantize physicsbody velocities server-side. Caused subs to occasionally not move horizontally because the velocities got rounded down to zero if the sub wasn't accelerating fast enough. --- .../Source/Characters/CharacterNetworking.cs | 4 +++- Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs index 5252292e5..3b8d62294 100644 --- a/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs @@ -383,7 +383,9 @@ namespace Barotrauma tempBuffer.Write(SimPosition.X); tempBuffer.Write(SimPosition.Y); float MaxVel = NetConfig.MaxPhysicsBodyVelocity; - AnimController.Collider.LinearVelocity = NetConfig.Quantize(AnimController.Collider.LinearVelocity, -MaxVel, MaxVel, 12); + AnimController.Collider.LinearVelocity = new Vector2( + MathHelper.Clamp(AnimController.Collider.LinearVelocity.X, -MaxVel, MaxVel), + MathHelper.Clamp(AnimController.Collider.LinearVelocity.Y, -MaxVel, MaxVel)); tempBuffer.WriteRangedSingle(AnimController.Collider.LinearVelocity.X, -MaxVel, MaxVel, 12); tempBuffer.WriteRangedSingle(AnimController.Collider.LinearVelocity.Y, -MaxVel, MaxVel, 12); diff --git a/Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs b/Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs index 10580b11e..aceb6ad85 100644 --- a/Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs +++ b/Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs @@ -33,13 +33,15 @@ namespace Barotrauma if (FarseerBody.Awake) { body.Enabled = true; - body.LinearVelocity = NetConfig.Quantize(body.LinearVelocity, -MaxVel, MaxVel, 12); + body.LinearVelocity = new Vector2( + MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), + MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel)); msg.WriteRangedSingle(body.LinearVelocity.X, -MaxVel, MaxVel, 12); msg.WriteRangedSingle(body.LinearVelocity.Y, -MaxVel, MaxVel, 12); if (!FarseerBody.FixedRotation) { - body.AngularVelocity = NetConfig.Quantize(body.AngularVelocity, -MaxAngularVel, MaxAngularVel, 8); - msg.WriteRangedSingle(MathHelper.Clamp(body.AngularVelocity, -MaxAngularVel, MaxAngularVel), -MaxAngularVel, MaxAngularVel, 8); + body.AngularVelocity = MathHelper.Clamp(body.AngularVelocity, -MaxAngularVel, MaxAngularVel); + msg.WriteRangedSingle(body.AngularVelocity, -MaxAngularVel, MaxAngularVel, 8); } }