Skip to content

Commit

Permalink
Prevent pull-moving (space-wizards#20502)
Browse files Browse the repository at this point in the history
  • Loading branch information
Partmedia authored Sep 26, 2023
1 parent f8e26ed commit e4de2fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Content.Server/Physics/Controllers/PullController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using Content.Shared.ActionBlocker;
using Content.Shared.Gravity;
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
Expand Down Expand Up @@ -37,6 +38,7 @@ public sealed class PullController : VirtualController
// How much you must move for the puller movement check to actually hit.
private const float MinimumMovementDistance = 0.005f;

[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly SharedPullingSystem _pullableSystem = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
Expand Down Expand Up @@ -191,9 +193,10 @@ public override void UpdateBeforeSolve(bool prediction, float frameTime)
var impulse = accel * physics.Mass * frameTime;
PhysicsSystem.ApplyLinearImpulse(pullableEnt, impulse, body: physics);

// if the puller is weightless, then we apply the inverse impulse.
// if the puller is weightless or can't move, then we apply the inverse impulse (Newton's third law).
// doing it under gravity produces an unsatisfying wiggling when pulling.
if (_gravity.IsWeightless(puller) && pullerXform.GridUid == null)
// If player can't move, assume they are on a chair and we need to prevent pull-moving.
if ((_gravity.IsWeightless(puller) && pullerXform.GridUid == null) || !_actionBlockerSystem.CanMove(puller))
{
PhysicsSystem.WakeBody(puller);
PhysicsSystem.ApplyLinearImpulse(puller, -impulse);
Expand Down

0 comments on commit e4de2fd

Please sign in to comment.