Fix pulling distance being too short (#2407)

This commit is contained in:
DrSmugleaf
2020-10-28 10:11:48 +01:00
committed by GitHub
parent c2301b08e0
commit 18572ed3f3
2 changed files with 16 additions and 21 deletions

View File

@@ -26,8 +26,6 @@ namespace Content.Shared.Physics.Pull
private IPhysicsComponent? _puller;
public bool GettingPulled => _puller != null;
private EntityCoordinates? _movingTo;
public IPhysicsComponent? Puller => _puller;
@@ -47,18 +45,6 @@ namespace Content.Shared.Physics.Pull
}
}
private float DistanceBeforeStopPull()
{
if (_puller == null)
{
return 0;
}
var aabbSize = _puller.AABB.Size;
return (aabbSize.X > aabbSize.Y ? aabbSize.X : aabbSize.Y) + 0.15f;
}
private bool PullerMovingTowardsPulled()
{
if (_puller == null)
@@ -83,7 +69,7 @@ namespace Content.Shared.Physics.Pull
var ray = new CollisionRay(origin, velocity, (int) CollisionGroup.AllMask);
bool Predicate(IEntity e) => e != ControlledComponent.Owner;
var rayResults =
_physicsManager.IntersectRayWithPredicate(mapId, ray, DistanceBeforeStopPull() * 2, Predicate);
_physicsManager.IntersectRayWithPredicate(mapId, ray, DistBeforeStopPull, Predicate);
return rayResults.Any();
}
@@ -219,13 +205,23 @@ namespace Content.Shared.Physics.Pull
var diff = MovingTo.Value.Position - ControlledComponent.Owner.Transform.Coordinates.Position;
LinearVelocity = diff.Normalized * 5;
}
else if (distance.Length > DistanceBeforeStopPull() && !PullerMovingTowardsPulled())
{
LinearVelocity = distance.Normalized * _puller.LinearVelocity.Length * 1.5f;
}
else
{
LinearVelocity = Vector2.Zero;
if (PullerMovingTowardsPulled())
{
LinearVelocity = Vector2.Zero;
return;
}
var distanceAbs = Vector2.Abs(distance);
var totalAabb = _puller.AABB.Size + ControlledComponent.AABB.Size / 2;
if (distanceAbs.X < totalAabb.X && distanceAbs.Y < totalAabb.Y)
{
LinearVelocity = Vector2.Zero;
return;
}
LinearVelocity = distance.Normalized * _puller.LinearVelocity.Length * 1.5f;
}
}