Better weightless yeeting and movement (#3573)

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-03-08 12:10:56 +11:00
committed by GitHub
parent fcb3498bba
commit 6f3860201c
5 changed files with 26 additions and 4 deletions

View File

@@ -17,7 +17,9 @@ namespace Content.Server.GameObjects.Components.Items
/// </summary> /// </summary>
/// <param name="entity"></param> /// <param name="entity"></param>
/// <param name="direction">Will use the vector's magnitude as the strength of the impulse</param> /// <param name="direction">Will use the vector's magnitude as the strength of the impulse</param>
internal static void TryThrow(this IEntity entity, Vector2 direction, IEntity? user = null) /// <param name="user"></param>
/// <param name="pushbackRatio">The ratio of impulse applied to the thrower</param>
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)) if (direction == Vector2.Zero || !entity.TryGetComponent(out PhysicsComponent? physicsComponent))
{ {
@@ -45,6 +47,11 @@ namespace Content.Server.GameObjects.Components.Items
} }
physicsComponent.ApplyLinearImpulse(direction); 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);
}
} }
} }
} }

View File

@@ -90,7 +90,7 @@ namespace Content.Server.GameObjects.Components.Movement
/// <inheritdoc /> /// <inheritdoc />
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float PushStrength { get; set; } public float PushStrength { get; set; } = 0.4f;
/// <inheritdoc /> /// <inheritdoc />
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]

View File

@@ -6,6 +6,7 @@ using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems.Click; using Content.Server.GameObjects.EntitySystems.Click;
using Content.Server.Interfaces.GameObjects.Components.Items; using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Input; using Content.Shared.Input;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
@@ -180,8 +181,17 @@ namespace Content.Server.GameObjects.EntitySystems
if (direction == Vector2.Zero) return true; if (direction == Vector2.Zero) return true;
direction = direction.Normalized * MathF.Min(direction.Length, 8.0f); 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; return true;
} }

View File

@@ -27,7 +27,7 @@ namespace Content.Shared.GameObjects.Components.Movement
[DataField("grabRange")] [DataField("grabRange")]
private float _grabRange = 0.2f; private float _grabRange = 0.2f;
[DataField("pushStrength")] [DataField("pushStrength")]
private float _pushStrength = 600.0f; private float _pushStrength = 0.4f;
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public EntityCoordinates LastPosition { get; set; } public EntityCoordinates LastPosition { get; set; }

View File

@@ -83,6 +83,11 @@ namespace Content.Shared.Physics.Controllers
// Target velocity. // Target velocity.
var total = (walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed); var total = (walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed);
if (weightless)
{
total *= mobMover.PushStrength;
}
if (total != Vector2.Zero) if (total != Vector2.Zero)
{ {
// This should have its event run during island solver soooo // This should have its event run during island solver soooo