From 18572ed3f33a7008171d01b7b085b93110786310 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Wed, 28 Oct 2020 10:11:48 +0100 Subject: [PATCH] Fix pulling distance being too short (#2407) --- .../Pulling/SharedPullableComponent.cs | 1 - Content.Shared/Physics/Pull/PullController.cs | 36 +++++++++---------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Content.Shared/GameObjects/Components/Pulling/SharedPullableComponent.cs b/Content.Shared/GameObjects/Components/Pulling/SharedPullableComponent.cs index d274c03140..aa566e7dfd 100644 --- a/Content.Shared/GameObjects/Components/Pulling/SharedPullableComponent.cs +++ b/Content.Shared/GameObjects/Components/Pulling/SharedPullableComponent.cs @@ -5,7 +5,6 @@ using Content.Shared.Physics.Pull; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; -using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Map; using Robust.Shared.Serialization; diff --git a/Content.Shared/Physics/Pull/PullController.cs b/Content.Shared/Physics/Pull/PullController.cs index cadb0db3ce..5884a0a6ff 100644 --- a/Content.Shared/Physics/Pull/PullController.cs +++ b/Content.Shared/Physics/Pull/PullController.cs @@ -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; } }