From 274fb4c6d2e8f505bdb344fd9b89a7fb033b7ac5 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 13 Jul 2021 18:21:09 +1000 Subject: [PATCH] Fix item dropping (#4259) * Fix item dropping * More optimal dropping --- .../Hands/Components/SharedHandsComponent.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Content.Shared/Hands/Components/SharedHandsComponent.cs b/Content.Shared/Hands/Components/SharedHandsComponent.cs index dbcafe26c1..1ebab628e4 100644 --- a/Content.Shared/Hands/Components/SharedHandsComponent.cs +++ b/Content.Shared/Hands/Components/SharedHandsComponent.cs @@ -441,14 +441,24 @@ namespace Content.Shared.Hands.Components var origin = Owner.Transform.MapPosition; var other = targetCoords.ToMap(Owner.EntityManager); + var dropVector = other.Position - origin.Position; + var requestedDropDistance = (dropVector.Length); + + if (dropVector.Length > SharedInteractionSystem.InteractionRange) + { + dropVector = dropVector.Normalized * SharedInteractionSystem.InteractionRange; + other = new MapCoordinates(origin.Position + dropVector, other.MapId); + } + var dropLength = EntitySystem.Get().UnobstructedDistance(origin, other, ignoredEnt: Owner); - dropLength = MathF.Min(dropLength, SharedInteractionSystem.InteractionRange); - var dropVector = origin.Position; - if (dropLength != 0) - dropVector += (other.Position - origin.Position).Normalized * dropLength; + var diff = requestedDropDistance - dropLength; - return targetCoords.WithPosition(dropVector); + // If we come up short then offset the drop location. + if (diff > 0) + return targetCoords.Offset(-dropVector.Normalized * diff); + + return targetCoords; } ///