Space Engineers

Space Engineers

Not enough ratings
Connector approach coordinates
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
791.000 B
21 Dec, 2017 @ 5:54am
1 Change Note ( view )

Subscribe to download
Connector approach coordinates

Description
Contains 2 functions to calculate gps coordinates to approach a connector. One with a distance in blocks, the other with a distance in meters (which uses the previous function, distance starts counting from the center of the connector).

It also contains functionality run this for all connectors on the grid and write the coordinates to a screen.

Purpose: To calculate the coordinates to align connectors with for automated docking.

--------------------------Explanation----------------------

It basically works by getting the grid coordinates (Connector.Position) of the connector block and then converting them to World Coordinates. (Using Connector.CubeGrid.GridIntegerToWorld())

That gives you the world coordinates of the connector itself.

Or, to get the front of the connector, you take Connector.Position and add the Forward vector of the connector (Base6Directions.GetIntVector(Connector.Orientation.Forward)), which you could multiply by a number of blocks, before converting all that to world coordinates.

That's what the first function in this script does.
Vector3D GetConnectorApproach(IMyShipConnector connector, int distanceBlocks).

You can call that function to get coordinates a number of blocks away from the connector, from the front of the connector, where you can connect to it.

The second function, (Vector3D GetConnectorApproach(IMyShipConnector connector, float distanceMeters)) uses the first function and then gets the length of the the difference between the connector offset and then normalizes it (to make it a vector with a length of 1 meter) and calculate basically the same thing, but you can specify the distance in meters, instead of blocks. Plus, you can use fractions of meters.

The functions here are basically meant to be copied and pasted into scripts where they're actually useful, like a script that tells drones where to go so they can dock.

------------The actual code of the functions-----------------

Vector3D GetConnectorApproach(IMyShipConnector connector, int distanceBlocks)
{
Vector3D coord = connector.CubeGrid.GridIntegerToWorld(connector.Position +
Base6Directions.GetIntVector(connector.Orientation.Forward) * distanceBlocks);
return coord;
}


Vector3D GetConnectorApproach(IMyShipConnector connector, float distanceMeters)
{
Vector3D v_con = connector.CubeGrid.GridIntegerToWorld(connector.Position);
Vector3D v_app = GetConnectorApproach(connector, 1);
Vector3D v_offset = v_app - v_con;
Vector3D v_normalized = v_offset / Math.Sqrt(v_offset.X * v_offset.X + v_offset.Y * v_offset.Y + v_offset.Z * v_offset.Z);
Vector3D coord = v_con + v_normalized * distanceMeters;
return coord;
}
6 Comments
Lazy Kitty  [author] 15 Mar, 2018 @ 11:52am 
@woostyboy You can use IMyRadioAntenna("message") to transmit a message. When a Radio Antenna that's linked to a programmable block receives it, it will run that antenna with "message" as the argument.
woostyboy 15 Mar, 2018 @ 4:16am 
No idea how to do that... :( Thanks though.
Lazy Kitty  [author] 16 Jan, 2018 @ 11:03am 
@woostyboy That's what it's meant for. You still need to add code to transmit the coordinates to your fighter, though.
woostyboy 16 Jan, 2018 @ 5:25am 
Hi, this looks brilliant but things like this blow my mind.... Can it guide a small grid fighter onto a large grid moving aircraft carrier for instance?
Thanks in advance.
Lazy Kitty  [author] 2 Jan, 2018 @ 1:48pm 
@Kyz6Me I've added a more thorough explanation as to how it works as well as copied the functions themselves into the description. I hope that helps.
The explanation didn't fit into a comment.
Kyz6Me 2 Jan, 2018 @ 11:54am 
Thank you for explaining how it works ? !