Skip to content

Commit

Permalink
Fix offset carrying
Browse files Browse the repository at this point in the history
Better fix Simple-Station#1
  • Loading branch information
Mnemotechnician committed Jun 24, 2024
1 parent 520cbaa commit 1348bb4
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Content.Server/Nyanotrasen/Carrying/CarryingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Numerics;
using System.Threading;
using Content.Server.DoAfter;
using Content.Server.Body.Systems;
Expand Down Expand Up @@ -64,7 +65,6 @@ public override void Initialize()
SubscribeLocalEvent<CarriableComponent, CarryDoAfterEvent>(OnDoAfter);
}


private void AddCarryVerb(EntityUid uid, CarriableComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
Expand Down Expand Up @@ -331,5 +331,32 @@ private float MassContest(EntityUid roller, EntityUid target, PhysicsComponent?

return rollerPhysics.FixturesMass / targetPhysics.FixturesMass;
}

public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<BeingCarriedComponent>();
while (query.MoveNext(out var carried, out var comp))
{
var carrier = comp.Carrier;
if (carrier is not { Valid: true } || carried is not { Valid: true })
continue;

// SOMETIMES - when an entity is inserted into disposals, or a cryosleep chamber - it can get re-parented without a proper reparent event
// when this happens, it needs to be dropped because it leads to weird behavior
if (Transform(carried).ParentUid != carrier)
{
DropCarried(carrier, carried);
continue;
}

// Make sure the carried entity is always centered relative to the carrier, as gravity pulls can offset it otherwise
var xform = Transform(carried);
if (!xform.LocalPosition.Equals(Vector2.Zero))
{
xform.LocalPosition = Vector2.Zero;
}
}
query.Dispose();
}
}
}

0 comments on commit 1348bb4

Please sign in to comment.