public void TakeControl(IMyControllableEntity entity) { if (ControlledEntity == entity) { return; } if (entity != null && entity.ControllerInfo.Controller != null) { Debug.Fail("Entity controlled by another controller, release it first"); return; } var old = ControlledEntity; if (old != null) { var entityCameraSettings = old.GetCameraEntitySettings(); float headLocalXAngle = old.HeadLocalXAngle; float headLocalYAngle = old.HeadLocalYAngle; old.Entity.OnClosing -= m_controlledEntityClosing; ControlledEntity = null; old.ControllerInfo.Controller = null; // This will call OnControlReleased bool firstPerson = entityCameraSettings != null? entityCameraSettings.IsFirstPerson : (MySession.GetCameraControllerEnum() != MyCameraControllerEnum.ThirdPersonSpectator); if (!MySandboxGame.IsDedicated) { MySession.Static.Cameras.SaveEntityCameraSettings( Player.Id, old.Entity.EntityId, firstPerson, MyThirdPersonSpectator.Static.GetDistance(), headLocalXAngle, headLocalYAngle); } } if (entity != null) { ControlledEntity = entity; ControlledEntity.Entity.OnClosing += m_controlledEntityClosing; ControlledEntity.ControllerInfo.Controller = this; // This will call OnControlAcquired if (!MySandboxGame.IsDedicated && ControlledEntity.Entity is Sandbox.ModAPI.Interfaces.IMyCameraController) { MySession.SetEntityCameraPosition(Player.Id, ControlledEntity.Entity); } } if (old != entity) { RaiseControlledEntityChanged(old, entity); } }