// Assume this is triggered when sensor detects player public void playerDetected() { //Echo("Player detected!"); for (int i = 0; i < doors.Count; i++) { IMyDoor door = doors[i]; Boolean anyoneNearDoor = false; for (int j = 0; j < sensors.Count; j++) { VRage.ModAPI.IMyEntity player = sensors[j].LastDetectedEntity; if (player == null) { continue; } //Echo("Checking player at " + player.GetPosition().ToString() + " against door " + door.CustomName); if ((player.GetPosition() - door.GetPosition()).Length() <= triggerDist) { anyoneNearDoor = true; break; } } if (anyoneNearDoor) { door.ApplyAction("Open_On"); } else { door.ApplyAction("Open_Off"); } } }
public override void UpdateBeforeSimulation10() { if (entrance_g == null) { return; } if (!entrance_g.IsFunctional || !entrance_g.IsWorking) { return; } string myname = entrance_g.CustomName; isportal = myname != null && myname.Contains("Portal"); if (isportal) { // MyAPIGateway.Utilities.ShowNotification("I am a Portal", 1000, MyFontEnum.Red); exit_g = GetNearestGateOnDifferentGrid(entrance_g); //if (exit_g != null) // MyAPIGateway.Utilities.ShowNotification("Found Portal", 2500); //else //MyAPIGateway.Utilities.ShowNotification("No portals found", 2500); //Sandbox.ModAPI.MyAPIGateway.Utilities.ShowNotification("UpdateBeforeSimulation10", 100); var player = MyAPIGateway.Session.Player.PlayerCharacter; if (MyAPIGateway.Session.Player.Controller.ControlledEntity != null) { player = MyAPIGateway.Session.Player.Controller.ControlledEntity; } //VRageMath.Vector3[] corners = m_gate.WorldAABB.GetCorners(); //VRageMath.BoundingBox box = m_gate.WorldAABB; //foreach (var corner in corners) //Sandbox.ModAPI.MyAPIGateway.Utilities.ShowNotification(String.Format("X={0}, Y={1}, Z={2}", corner.X, corner.Y, corner.Z, 5000)); // Check if player position is at event horizon // This distance is based on local origin point for the model and player/cockpit // A more accurate method would be to constrain the bounds to the plane parallel // to the gate and through the center, and within the bounding box of the model. float distance = (player.Entity.GetPosition() - entrance_g.GetPosition()).Length(); //MyAPIGateway.Utilities.ShowNotification("Distance from Portal = " + distance, 2500); if (distance < 1.8f && isactive && exit_g != null) { MyAPIGateway.Utilities.ShowNotification("This is a portal", 1000, MyFontEnum.Red); VRageMath.Vector3 pos = exit_g.GetPosition(); if (player.Entity.EntityId == MyAPIGateway.Session.Player.PlayerCharacter.Entity.EntityId) { pos += (exit_g.WorldMatrixNormalizedInv.Forward * 2); pos += (exit_g.WorldMatrixNormalizedInv.Down * 2); } else { pos += (exit_g.WorldMatrixNormalizedInv.Forward * 10); } player.Entity.GetTopMostParent().SetPosition(pos); // TODO set player orientation // Enable gate shutdown timer WasUsed = true; } } }
public Vector3 getPosition() { return(door.GetPosition()); }