Fix thrown entities getting parented to player parent (#4528)

This commit is contained in:
ShadowCommander
2021-08-25 03:35:37 -07:00
committed by GitHub
parent 745a2138fe
commit 1ce9645ebe

View File

@@ -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
/// <summary>
/// Calculates the final location a dropped item will end up at, accounting for max drop range and collision along the targeted drop path.
/// </summary>
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<SharedInteractionSystem>().UnobstructedDistance(origin, other, ignoredEnt: Owner);
var dropLength = EntitySystem.Get<SharedInteractionSystem>().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;
}
/// <summary>