Advertisement
xmuni

Space Engineers Location Finder Script

Aug 31st, 2015
3,410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. // Script to get the position of an object if you know the distance.
  2. // Type the distance (in meters) into the argument box of the programmable block.
  3.  
  4. string name_origin = "Block origin";
  5. string name_forward = "Camera forward";
  6. string name_panel = "Text panel position";
  7.  
  8. void Main(string argument)
  9. {
  10.     if(argument=="")
  11.         throw new Exception("\nType the distance into the argument box.");
  12.    
  13.     int distance = Convert.ToInt32(argument);
  14.    
  15.     Vector3D origin = getblock(name_origin).GetPosition();
  16.     Vector3D forward = getblock(name_forward).GetPosition();
  17.     IMyTextPanel panel = getblock(name_panel) as IMyTextPanel;
  18.    
  19.     Vector3D position = forward - ((origin - forward) * distance / Vector3D.Distance(origin, forward));
  20.    
  21.     string x = "X: " + (position.GetDim(0)).ToString("N0");
  22.     string y = "Y: " + (position.GetDim(1)).ToString("N0");
  23.     string z = "Z: " + (position.GetDim(2)).ToString("N0");
  24.    
  25.     string text = x+"\n"+y+"\n"+z;
  26.    
  27.     panel.WritePublicText(text, false);
  28. }
  29.  
  30. IMyTerminalBlock getblock(string name)
  31. {
  32.     List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
  33.     GridTerminalSystem.SearchBlocksOfName(name, blocks);
  34.    
  35.     if(blocks.Count>0)
  36.         return blocks[0];
  37.    
  38.     throw new Exception("\nBlock not found: "+name);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement