From 1ce9645ebe7fb4671b941f40e17661011b43e357 Mon Sep 17 00:00:00 2001
From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Date: Wed, 25 Aug 2021 03:35:37 -0700
Subject: [PATCH] Fix thrown entities getting parented to player parent (#4528)
---
.../Hands/Components/SharedHandsComponent.cs | 24 ++++++++-----------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/Content.Shared/Hands/Components/SharedHandsComponent.cs b/Content.Shared/Hands/Components/SharedHandsComponent.cs
index d698336476..0eb370bc22 100644
--- a/Content.Shared/Hands/Components/SharedHandsComponent.cs
+++ b/Content.Shared/Hands/Components/SharedHandsComponent.cs
@@ -437,7 +437,7 @@ namespace Content.Shared.Hands.Components
DoDroppedInteraction(heldEntity, intentionalDrop);
- heldEntity.Transform.Coordinates = GetFinalDropCoordinates(targetDropLocation);
+ heldEntity.Transform.WorldPosition = GetFinalDropCoordinates(targetDropLocation);
OnItemChanged?.Invoke();
}
@@ -445,29 +445,25 @@ namespace Content.Shared.Hands.Components
///
/// Calculates the final location a dropped item will end up at, accounting for max drop range and collision along the targeted drop path.
///
- private EntityCoordinates GetFinalDropCoordinates(EntityCoordinates targetCoords)
+ private Vector2 GetFinalDropCoordinates(EntityCoordinates targetCoords)
{
var origin = Owner.Transform.MapPosition;
- var other = targetCoords.ToMap(Owner.EntityManager);
+ var target = targetCoords.ToMap(Owner.EntityManager);
- var dropVector = other.Position - origin.Position;
- var requestedDropDistance = (dropVector.Length);
+ var dropVector = target.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);
+ target = new MapCoordinates(origin.Position + dropVector, target.MapId);
}
- var dropLength = EntitySystem.Get().UnobstructedDistance(origin, other, ignoredEnt: Owner);
+ var dropLength = EntitySystem.Get().UnobstructedDistance(origin, target, ignoredEnt: Owner);
- var diff = requestedDropDistance - dropLength;
-
- // If we come up short then offset the drop location.
- if (diff > 0)
- return targetCoords.Offset(-dropVector.Normalized * diff);
-
- return targetCoords;
+ if (dropLength < requestedDropDistance)
+ return origin.Position + dropVector.Normalized * dropLength;
+ return target.Position;
}
///