From 6f3860201c5b5db4f7d777e3c78d4c7ede114237 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 8 Mar 2021 12:10:56 +1100 Subject: [PATCH] Better weightless yeeting and movement (#3573) Co-authored-by: Metal Gear Sloth --- .../GameObjects/Components/Items/ThrowHelper.cs | 9 ++++++++- .../Components/Movement/AiControllerComponent.cs | 2 +- .../GameObjects/EntitySystems/HandsSystem.cs | 12 +++++++++++- .../Movement/SharedPlayerMobMoverComponent.cs | 2 +- .../Physics/Controllers/SharedMoverController.cs | 5 +++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Content.Server/GameObjects/Components/Items/ThrowHelper.cs b/Content.Server/GameObjects/Components/Items/ThrowHelper.cs index 6f476c0b96..b1b641f34d 100644 --- a/Content.Server/GameObjects/Components/Items/ThrowHelper.cs +++ b/Content.Server/GameObjects/Components/Items/ThrowHelper.cs @@ -17,7 +17,9 @@ namespace Content.Server.GameObjects.Components.Items /// /// /// Will use the vector's magnitude as the strength of the impulse - internal static void TryThrow(this IEntity entity, Vector2 direction, IEntity? user = null) + /// + /// The ratio of impulse applied to the thrower + internal static void TryThrow(this IEntity entity, Vector2 direction, IEntity? user = null, float pushbackRatio = 1.0f) { if (direction == Vector2.Zero || !entity.TryGetComponent(out PhysicsComponent? physicsComponent)) { @@ -45,6 +47,11 @@ namespace Content.Server.GameObjects.Components.Items } physicsComponent.ApplyLinearImpulse(direction); + // Give thrower an impulse in the other direction + if (user != null && pushbackRatio > 0.0f && user.TryGetComponent(out IPhysBody? body)) + { + body.ApplyLinearImpulse(-direction * pushbackRatio); + } } } } diff --git a/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs b/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs index e36ad5aa7d..dab617671d 100644 --- a/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs @@ -90,7 +90,7 @@ namespace Content.Server.GameObjects.Components.Movement /// [ViewVariables(VVAccess.ReadWrite)] - public float PushStrength { get; set; } + public float PushStrength { get; set; } = 0.4f; /// [ViewVariables(VVAccess.ReadWrite)] diff --git a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs index 0c2ac9802e..4461a2e73a 100644 --- a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs @@ -6,6 +6,7 @@ using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems.Click; using Content.Server.Interfaces.GameObjects.Components.Items; +using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Input; using Content.Shared.Interfaces; @@ -180,8 +181,17 @@ namespace Content.Server.GameObjects.EntitySystems if (direction == Vector2.Zero) return true; direction = direction.Normalized * MathF.Min(direction.Length, 8.0f); + var yeet = direction * ThrowForce * 15; - throwEnt.TryThrow(direction * ThrowForce * 15, playerEnt); + // Softer yeet in weightlessness + if (playerEnt.IsWeightless()) + { + throwEnt.TryThrow(yeet / 4, playerEnt, 10.0f); + } + else + { + throwEnt.TryThrow(yeet, playerEnt); + } return true; } diff --git a/Content.Shared/GameObjects/Components/Movement/SharedPlayerMobMoverComponent.cs b/Content.Shared/GameObjects/Components/Movement/SharedPlayerMobMoverComponent.cs index b982433d94..410504d9bf 100644 --- a/Content.Shared/GameObjects/Components/Movement/SharedPlayerMobMoverComponent.cs +++ b/Content.Shared/GameObjects/Components/Movement/SharedPlayerMobMoverComponent.cs @@ -27,7 +27,7 @@ namespace Content.Shared.GameObjects.Components.Movement [DataField("grabRange")] private float _grabRange = 0.2f; [DataField("pushStrength")] - private float _pushStrength = 600.0f; + private float _pushStrength = 0.4f; [ViewVariables(VVAccess.ReadWrite)] public EntityCoordinates LastPosition { get; set; } diff --git a/Content.Shared/Physics/Controllers/SharedMoverController.cs b/Content.Shared/Physics/Controllers/SharedMoverController.cs index 52ffecfe67..c1a12bb975 100644 --- a/Content.Shared/Physics/Controllers/SharedMoverController.cs +++ b/Content.Shared/Physics/Controllers/SharedMoverController.cs @@ -83,6 +83,11 @@ namespace Content.Shared.Physics.Controllers // Target velocity. var total = (walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed); + if (weightless) + { + total *= mobMover.PushStrength; + } + if (total != Vector2.Zero) { // This should have its event run during island solver soooo