/// <summary> /// Docks 2 ports together and assumes it is valid. /// </summary> public void Dock(DockingComponent dockA, DockingComponent dockB) { _sawmill.Debug($"Docking between {dockA.Owner} and {dockB.Owner}"); // https://gamedev.stackexchange.com/questions/98772/b2distancejoint-with-frequency-equal-to-0-vs-b2weldjoint // We could also potentially use a prismatic joint? Depending if we want clamps that can extend or whatever var dockAXform = EntityManager.GetComponent <TransformComponent>(dockA.Owner); var dockBXform = EntityManager.GetComponent <TransformComponent>(dockB.Owner); DebugTools.Assert(dockAXform.GridUid != null); DebugTools.Assert(dockBXform.GridUid != null); var gridA = dockAXform.GridUid !.Value; var gridB = dockBXform.GridUid !.Value; SharedJointSystem.LinearStiffness( 2f, 0.7f, EntityManager.GetComponent <PhysicsComponent>(gridA).Mass, EntityManager.GetComponent <PhysicsComponent>(gridB).Mass, out var stiffness, out var damping); // These need playing around with // Could also potentially have collideconnected false and stiffness 0 but it was a bit more suss??? var joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, DockingJoint + dockA.Owner); var gridAXform = EntityManager.GetComponent <TransformComponent>(gridA); var gridBXform = EntityManager.GetComponent <TransformComponent>(gridB); var anchorA = dockAXform.LocalPosition + dockAXform.LocalRotation.ToWorldVec() / 2f; var anchorB = dockBXform.LocalPosition + dockBXform.LocalRotation.ToWorldVec() / 2f; joint.LocalAnchorA = anchorA; joint.LocalAnchorB = anchorB; joint.ReferenceAngle = (float)(gridBXform.WorldRotation - gridAXform.WorldRotation); joint.CollideConnected = true; joint.Stiffness = stiffness; joint.Damping = damping; dockA.DockedWith = dockB.Owner; dockB.DockedWith = dockA.Owner; dockA.DockJoint = joint; dockB.DockJoint = joint; if (TryComp(dockA.Owner, out DoorComponent? doorA)) { doorA.ChangeAirtight = false; _doorSystem.StartOpening(doorA.Owner, doorA); } if (TryComp(dockB.Owner, out DoorComponent? doorB)) { doorB.ChangeAirtight = false; _doorSystem.StartOpening(doorB.Owner, doorB); } var msg = new DockEvent { DockA = dockA, DockB = dockB, GridAUid = gridA, GridBUid = gridB, }; EntityManager.EventBus.RaiseLocalEvent(dockA.Owner, msg, false); EntityManager.EventBus.RaiseLocalEvent(dockB.Owner, msg, false); EntityManager.EventBus.RaiseEvent(EventSource.Local, msg); }