From 5ade8c2695e56a7cc1b3b30e05f146d603000e3f Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Thu, 2 Sep 2021 12:35:16 +1000 Subject: [PATCH] Fix pulling lerping (#4550) --- .../Physics/Controllers/MoverController.cs | 27 +++++++++++++++++++ .../EntitySystems/SharedMoverSystem.cs | 3 ++- .../Movement/SharedMoverController.cs | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Content.Client/Physics/Controllers/MoverController.cs b/Content.Client/Physics/Controllers/MoverController.cs index 9b53311e91..77148fec6d 100644 --- a/Content.Client/Physics/Controllers/MoverController.cs +++ b/Content.Client/Physics/Controllers/MoverController.cs @@ -1,5 +1,8 @@ +using Content.Shared.Body.Components; +using Content.Shared.MobState; using Content.Shared.Movement; using Content.Shared.Movement.Components; +using Content.Shared.Pulling.Components; using Robust.Client.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -32,6 +35,30 @@ namespace Content.Client.Physics.Controllers joint.BodyB.Predict = true; } + // If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother. + if (player.TryGetComponent(out SharedPullableComponent? pullableComp)) + { + var puller = pullableComp.Puller; + if (puller != null && puller.TryGetComponent(out var pullerBody)) + { + pullerBody.Predict = false; + body.Predict = false; + } + } + + // If we're pulling a mob then make sure that isn't predicted so it doesn't fuck our velocity up. + if (player.TryGetComponent(out SharedPullerComponent? pullerComp)) + { + var pulling = pullerComp.Pulling; + + if (pulling != null && + pulling.HasComponent() && + pulling.TryGetComponent(out PhysicsComponent? pullingBody)) + { + pullingBody.Predict = false; + } + } + // Server-side should just be handled on its own so we'll just do this shizznit if (player.TryGetComponent(out IMobMoverComponent? mobMover)) { diff --git a/Content.Shared/Movement/EntitySystems/SharedMoverSystem.cs b/Content.Shared/Movement/EntitySystems/SharedMoverSystem.cs index f722531c91..9ab8e4a474 100644 --- a/Content.Shared/Movement/EntitySystems/SharedMoverSystem.cs +++ b/Content.Shared/Movement/EntitySystems/SharedMoverSystem.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using System.Linq; using Content.Shared.MobState; using Content.Shared.Movement.Components; using Robust.Shared.Containers; @@ -49,7 +50,7 @@ namespace Content.Shared.Movement.EntitySystems if (owner != null && session != null) { - foreach (var comp in owner.GetAllComponents()) + foreach (var comp in owner.GetAllComponents().ToArray()) { comp.MoveInputPressed(session); } diff --git a/Content.Shared/Movement/SharedMoverController.cs b/Content.Shared/Movement/SharedMoverController.cs index 6d4f5666f5..d6dadc28d1 100644 --- a/Content.Shared/Movement/SharedMoverController.cs +++ b/Content.Shared/Movement/SharedMoverController.cs @@ -152,6 +152,8 @@ namespace Content.Shared.Movement { return body.BodyStatus == BodyStatus.OnGround && body.Owner.HasComponent() && + // If we're being pulled then don't mess with our velocity. + (!body.Owner.TryGetComponent(out SharedPullableComponent? pullable) || !pullable.BeingPulled) && _blocker.CanMove(body.Owner); }