diff --git a/Content.Server/Physics/Controllers/PullController.cs b/Content.Server/Physics/Controllers/PullController.cs index c02669bb0a..1978036cfa 100644 --- a/Content.Server/Physics/Controllers/PullController.cs +++ b/Content.Server/Physics/Controllers/PullController.cs @@ -65,15 +65,17 @@ namespace Content.Server.Physics.Controllers continue; } - if (pullable.Puller == null) + var puller = pullable.Puller; + if (puller == null) { continue; } // Now that's over with... - var pullerPosition = pullable.Puller!.Transform.MapPosition; - if (pullable.MovingTo.Value.MapId != pullerPosition.MapId) + var pullerPosition = puller.Transform.MapPosition; + var movingTo = pullable.MovingTo.Value.ToMap(pullable.Owner.EntityManager); + if (movingTo.MapId != pullerPosition.MapId) { _pullableSystem.StopMoveTo(pullable); continue; @@ -81,13 +83,13 @@ namespace Content.Server.Physics.Controllers if (!pullable.Owner.TryGetComponent(out var physics) || physics.BodyType == BodyType.Static || - pullable.MovingTo.Value.MapId != pullable.Owner.Transform.MapID) + movingTo.MapId != pullable.Owner.Transform.MapID) { _pullableSystem.StopMoveTo(pullable); continue; } - var movingPosition = pullable.MovingTo.Value.Position; + var movingPosition = movingTo.Position; var ownerPosition = pullable.Owner.Transform.MapPosition.Position; var diff = movingPosition - ownerPosition; @@ -113,7 +115,14 @@ namespace Content.Server.Physics.Controllers accel -= physics.LinearVelocity * SettleShutdownMultiplier * scaling; } physics.WakeBody(); - physics.ApplyLinearImpulse(accel * physics.Mass * frameTime); + var impulse = accel * physics.Mass * frameTime; + physics.ApplyLinearImpulse(impulse); + + if (puller.TryGetComponent(out var pullerPhysics)) + { + pullerPhysics.WakeBody(); + pullerPhysics.ApplyLinearImpulse(-impulse); + } } } } diff --git a/Content.Shared/Pulling/Components/PullableComponent.cs b/Content.Shared/Pulling/Components/PullableComponent.cs index eddc1099c6..6f0239ca6d 100644 --- a/Content.Shared/Pulling/Components/PullableComponent.cs +++ b/Content.Shared/Pulling/Components/PullableComponent.cs @@ -36,7 +36,7 @@ namespace Content.Shared.Pulling.Components public bool BeingPulled => Puller != null; - public MapCoordinates? MovingTo { get; set; } + public EntityCoordinates? MovingTo { get; set; } public override ComponentState GetComponentState(ICommonSession player) { diff --git a/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs b/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs index 2244c1aa7c..7a0a2d50ed 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs @@ -140,7 +140,7 @@ namespace Content.Shared.Pulling ForceRelationship(null, pullable); } - public void ForceSetMovingTo(SharedPullableComponent pullable, MapCoordinates? movingTo) + public void ForceSetMovingTo(SharedPullableComponent pullable, EntityCoordinates? movingTo) { if (pullable.MovingTo == movingTo) { diff --git a/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs b/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs index 18962ccdf8..adab67979d 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs @@ -172,7 +172,7 @@ namespace Content.Shared.Pulling return true; } - public bool TryMoveTo(SharedPullableComponent pullable, MapCoordinates to) + public bool TryMoveTo(SharedPullableComponent pullable, EntityCoordinates to) { if (pullable.Puller == null) { diff --git a/Content.Shared/Pulling/Systems/SharedPullingSystem.cs b/Content.Shared/Pulling/Systems/SharedPullingSystem.cs index 79663d8d8e..25c2181407 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingSystem.cs @@ -47,8 +47,9 @@ namespace Content.Shared.Pulling /// If difference between puller and pulled angle lower that this threshold, /// pulled entity will not change its rotation. /// Helps with diagonal movement jittering + /// As of further adjustments, should divide cleanly into 90 degrees /// - private const float ThresholdRotAngle = 30; + private const float ThresholdRotAngle = 22.5f; public IReadOnlySet Moving => _moving; @@ -177,11 +178,6 @@ namespace Content.Shared.Pulling UpdatePulledRotation(puller, pulled); physics.WakeBody(); - - if (pulled.TryGetComponent(out SharedPullableComponent? pullable)) - { - _pullSm.ForceSetMovingTo(pullable, null); - } } // TODO: When Joint networking is less shitcodey fix this to use a dedicated joints message. @@ -224,7 +220,7 @@ namespace Content.Shared.Pulling return false; } - TryMoveTo(pullable, coords.ToMap(EntityManager)); + TryMoveTo(pullable, coords); return false; } @@ -270,8 +266,17 @@ namespace Content.Shared.Pulling var newAngle = Angle.FromWorldVec(dir); var diff = newAngle - oldAngle; - if (Math.Abs(diff.Degrees) > ThresholdRotAngle) - pulled.Transform.WorldRotation = newAngle; + if (Math.Abs(diff.Degrees) > (ThresholdRotAngle / 2f)) + { + // Ok, so this bit is difficult because ideally it would look like it's snapping to sane angles. + // Otherwise PIANO DOOR STUCK! happens. + // But it also needs to work with station rotation / align to the local parent. + // So... + var baseRotation = pulled.Transform.Parent?.WorldRotation ?? 0f; + var localRotation = newAngle - baseRotation; + var localRotationSnapped = Angle.FromDegrees(Math.Floor((localRotation.Degrees / ThresholdRotAngle) + 0.5f) * ThresholdRotAngle); + pulled.Transform.LocalRotation = localRotationSnapped; + } } } }