Fix pulling distance being too short (#2407)
This commit is contained in:
@@ -5,7 +5,6 @@ using Content.Shared.Physics.Pull;
|
|||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects.Components.Transform;
|
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ namespace Content.Shared.Physics.Pull
|
|||||||
|
|
||||||
private IPhysicsComponent? _puller;
|
private IPhysicsComponent? _puller;
|
||||||
|
|
||||||
public bool GettingPulled => _puller != null;
|
|
||||||
|
|
||||||
private EntityCoordinates? _movingTo;
|
private EntityCoordinates? _movingTo;
|
||||||
|
|
||||||
public IPhysicsComponent? Puller => _puller;
|
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()
|
private bool PullerMovingTowardsPulled()
|
||||||
{
|
{
|
||||||
if (_puller == null)
|
if (_puller == null)
|
||||||
@@ -83,7 +69,7 @@ namespace Content.Shared.Physics.Pull
|
|||||||
var ray = new CollisionRay(origin, velocity, (int) CollisionGroup.AllMask);
|
var ray = new CollisionRay(origin, velocity, (int) CollisionGroup.AllMask);
|
||||||
bool Predicate(IEntity e) => e != ControlledComponent.Owner;
|
bool Predicate(IEntity e) => e != ControlledComponent.Owner;
|
||||||
var rayResults =
|
var rayResults =
|
||||||
_physicsManager.IntersectRayWithPredicate(mapId, ray, DistanceBeforeStopPull() * 2, Predicate);
|
_physicsManager.IntersectRayWithPredicate(mapId, ray, DistBeforeStopPull, Predicate);
|
||||||
|
|
||||||
return rayResults.Any();
|
return rayResults.Any();
|
||||||
}
|
}
|
||||||
@@ -219,13 +205,23 @@ namespace Content.Shared.Physics.Pull
|
|||||||
var diff = MovingTo.Value.Position - ControlledComponent.Owner.Transform.Coordinates.Position;
|
var diff = MovingTo.Value.Position - ControlledComponent.Owner.Transform.Coordinates.Position;
|
||||||
LinearVelocity = diff.Normalized * 5;
|
LinearVelocity = diff.Normalized * 5;
|
||||||
}
|
}
|
||||||
else if (distance.Length > DistanceBeforeStopPull() && !PullerMovingTowardsPulled())
|
|
||||||
{
|
|
||||||
LinearVelocity = distance.Normalized * _puller.LinearVelocity.Length * 1.5f;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (PullerMovingTowardsPulled())
|
||||||
{
|
{
|
||||||
LinearVelocity = Vector2.Zero;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user