1
0

BoundarySystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using Content.Shared.Movement.Components;
  2. using Robust.Shared.Physics.Events;
  3. namespace Content.Server.Movement.Systems;
  4. public sealed class BoundarySystem : EntitySystem
  5. {
  6. /*
  7. * The real reason this even exists is because with out mover controller it's really easy to clip out of bounds on chain shapes.
  8. */
  9. [Dependency] private readonly SharedTransformSystem _xform = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<BoundaryComponent, StartCollideEvent>(OnBoundaryCollide);
  14. }
  15. private void OnBoundaryCollide(Entity<BoundaryComponent> ent, ref StartCollideEvent args)
  16. {
  17. var center = _xform.GetWorldPosition(ent.Owner);
  18. var otherXform = Transform(args.OtherEntity);
  19. var collisionPoint = _xform.GetWorldPosition(otherXform);
  20. var offset = collisionPoint - center;
  21. offset = offset.Normalized() * (offset.Length() - ent.Comp.Offset);
  22. // If for whatever reason you want to yeet them to the other side.
  23. // offset = new Angle(MathF.PI).RotateVec(offset);
  24. _xform.SetWorldPosition(otherXform, center + offset);
  25. }
  26. }