Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Script to get the position of an object if you know the distance.
- // Type the distance (in meters) into the argument box of the programmable block.
- string name_origin = "Block origin";
- string name_forward = "Camera forward";
- string name_panel = "Text panel position";
- void Main(string argument)
- {
- if(argument=="")
- throw new Exception("\nType the distance into the argument box.");
- int distance = Convert.ToInt32(argument);
- Vector3D origin = getblock(name_origin).GetPosition();
- Vector3D forward = getblock(name_forward).GetPosition();
- IMyTextPanel panel = getblock(name_panel) as IMyTextPanel;
- Vector3D position = forward - ((origin - forward) * distance / Vector3D.Distance(origin, forward));
- string x = "X: " + (position.GetDim(0)).ToString("N0");
- string y = "Y: " + (position.GetDim(1)).ToString("N0");
- string z = "Z: " + (position.GetDim(2)).ToString("N0");
- string text = x+"\n"+y+"\n"+z;
- panel.WritePublicText(text, false);
- }
- IMyTerminalBlock getblock(string name)
- {
- List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName(name, blocks);
- if(blocks.Count>0)
- return blocks[0];
- throw new Exception("\nBlock not found: "+name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement