Fix ghosts following a moving entity causing them to be offset (#22783)

Fixes #14220

Because the entity they start following is moving, the physics system gives the follower opposing velocity to counteract, at the time the parent change happens. This happens *after* the follower system tries to clear the follower's velocity, so the follower gets some velocity that will still move them a bit off-center.

Fix is easy enough, just reset velocity *after* reparenting, not before.
This commit is contained in:
Pieter-Jan Briers
2023-12-21 00:33:00 +01:00
committed by GitHub
parent 3f3669712f
commit 5e6f350731

View File

@@ -162,8 +162,6 @@ public sealed class FollowerSystem : EntitySystem
if (TryComp<JointComponent>(follower, out var joints))
_jointSystem.ClearJoints(follower, joints);
_physicsSystem.SetLinearVelocity(follower, Vector2.Zero);
var xform = Transform(follower);
_containerSystem.AttachParentToContainerOrGrid((follower, xform));
@@ -173,6 +171,8 @@ public sealed class FollowerSystem : EntitySystem
_transform.SetCoordinates(follower, xform, new EntityCoordinates(entity, Vector2.Zero), rotation: Angle.Zero);
}
_physicsSystem.SetLinearVelocity(follower, Vector2.Zero);
EnsureComp<OrbitVisualsComponent>(follower);
var followerEv = new StartedFollowingEntityEvent(entity, follower);