Fix item dropping (#4259)

* Fix item dropping

* More optimal dropping
This commit is contained in:
metalgearsloth
2021-07-13 18:21:09 +10:00
committed by GitHub
parent 65daba185e
commit 274fb4c6d2

View File

@@ -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<SharedInteractionSystem>().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;
}
/// <summary>