public override void UpdateAfterSimulation10() { base.UpdateAfterSimulation10(); if (!Sync.IsServer || !IsWorking || !PowerReceiver.IsPowered) { return; } var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up); var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax + m_fieldMin) * 0.5f, rotation1); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field"); if (m_recreateField) { m_recreateField = false; m_fieldShape.RemoveReference(); m_fieldShape = GetHkShape(); PowerReceiver.Update(); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); var boundingBox = new BoundingBoxD(m_fieldMin, m_fieldMax).Translate(PositionComp.LocalVolume.Center).Transform(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition()); m_potentialPenetrations.Clear(); MyGamePruningStructure.GetAllSensableEntitiesInBox <MyEntity>(ref boundingBox, m_potentialPenetrations); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics"); LastDetectedEntity = null; if (IsActive) { bool empty = true; foreach (var entity in m_potentialPenetrations) { if (ShouldDetect(entity)) { if (entity.Physics == null || !entity.Physics.Enabled) { continue; } Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (entity.Physics.RigidBody != null) { shape2 = entity.Physics.RigidBody.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; if (entity is MyVoxelMap) { var voxel = entity as MyVoxelMap; posDiff -= voxel.Storage.Size / 2; } } else if (entity.Physics.CharacterProxy != null) { shape2 = entity.Physics.CharacterProxy.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; } else { continue; } if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; empty = false; break; } } } if (empty) { IsActive = false; } } else { foreach (var entity in m_potentialPenetrations) { if (ShouldDetect(entity)) { if (entity.Physics == null || !entity.Physics.Enabled) { continue; } Quaternion rotation2; Vector3 posDiff; HkShape? shape2; if (entity.Physics.RigidBody != null) { shape2 = entity.Physics.RigidBody.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; if (entity is MyVoxelMap) { var voxel = entity as MyVoxelMap; posDiff -= voxel.Storage.Size / 2; } } else if (entity.Physics.CharacterProxy != null) { shape2 = entity.Physics.CharacterProxy.GetShape(); var worldMatrix = entity.WorldMatrix; rotation2 = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); posDiff = entity.PositionComp.GetPosition() - position1; } else { continue; } if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { LastDetectedEntity = entity; IsActive = true; break; } } } } m_potentialPenetrations.Clear(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }