Space Engineers

Space Engineers

Not enough ratings
Single-Camera Rangefinder [Obsolete!]
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
3.104 KB
18 Aug, 2015 @ 8:54pm
7 Jul, 2017 @ 12:31pm
6 Change Notes ( view )

Subscribe to download
Single-Camera Rangefinder [Obsolete!]

Description
Note that camera raycasting pretty much makes this script obsolete. I'm sure raycast rangefinders are a dime a dozen. I won't bother releasing a standalone rangefinder, but I am beginning to incorporate raycasting into my other scripts (e.g. fire control systems, target trackers, etc.)


This script implements a parallax rangefinder[en.wikipedia.org] using only one camera. It achieves this by taking two lines from a fixed reference point on your ship (taken at two different times) and calculating the closest point of approach between those two lines. This, of course, means your ship needs to be reasonably mobile.

Same idea as my Rotor-based parallax rangefinder script ...but without the rotor. :P

Not a unique idea, not the first time this was done. Credit goes to jhnwgacy's GPS guided torpedoes where I first saw this idea. Though my implementation was written from scratch (so I could learn the math) and only uses a single script.

Personally, I use this script on a small utility ship to get the range to the next interesting-looking asteroid. Then I can blind jump with reasonable accuracy (I don't bother entering the GPS coords, I just use the range).

(Of course, you could also use it for weapons. I modified Whiplash141's https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=452149353 to fire guided kinetic missiles, for example.)

Setup

Required: Programmable block, camera, and some sort of controller block (cockpit or remote control, for example)
  1. Put the controller block in a group named Reference
  2. Put the camera somewhere in front of this controller block. It should be inline with the controller block otherwise the crosshairs you see will not be centered!
  3. Load script into programmable block
Usage

You must run the programmable block using arguments, so it is best to set these up on your cockpit/remote toolbar.
  1. If you are using a remote control as reference, be sure to control that remote first.
  2. Look through the camera and aim your ship at whatever object you want to get the range/coordinates of
  3. Run the programmable block with argument first (or no argument at all)
  4. Move your ship laterally (left/right/up/down). If you move it forward/back, don't worry, it will still work. But the farther you move laterally, the more accurate it will be.
  5. Look through the camera again and try to aim at the same exact point you aimed at above.
  6. Run the programmable block with argument second
The script will then search for all text blocks in the group CM Target and write the coordinates in the form "X;Y;Z" (remember, for this to work these text panels must have the same ownership as the programmable block)

Additionally, if you select the programmable block in the terminal, it will show you the GPS coordinates and distance on the right side of the terminal.

Configurables

The reference group, text panel target group, and text panel coordinate format can be edited at the top of the script. Additionally, if you're familiar with C#, you can edit the TargetAction method to do whatever you want with the target coordinates (the Vector3D parameter).

The text panel coordinate format is meant to be easily parsed by a script. However, changing it to the following is also very useful:
const string RANGEFINDER_TARGET_FORMAT = "GPS:Whatever:{0}:{1}:{2}:";
This is the same format that Space Engineers uses when copying & pasting GPS coordinates. This will allow you to automatically add a temporary GPS position by simply editing or looking at the text panel's public text. (After doing so, it should show up as a light gray coordinate in your GPS list.)

The calculated distance is accessible by using the placeholder "{3}"

Source

For the bleeding edge, as well as a more readable and modular version of the script, go see GitHub[github.com]. I usually only update the workshop version when things break or major features are added.
19 Comments
ZerothAngel  [author] 7 Jul, 2017 @ 12:39pm 
I just published an update to make that possible. The default behavior hasn't changed though, so you will have to edit RANGEFINDER_TARGET_FORMAT as mentioned above.

For example:

const string RANGEFINDER_TARGET_FORMAT = "{3}";

will just output the raw range (and only the range) to all text panels in the CM Target group. You can add whatever embellishments you like, like "Range: {3} m" or (what I would use) "Range: {3:F2} m" (the latter will round to 2 decimal places)
Quartofel 7 Jul, 2017 @ 12:02pm 
Will you consider displaying the range on the LCD instead of coordinates. "Dry" range would be more useful in combat scenario.
jokerace45 20 May, 2017 @ 6:10pm 
Is this Script still relevent ? Or has it become outdated ?
ZerothAngel  [author] 12 Dec, 2016 @ 1:21pm 
@DeeBee If you're familiar with C#, have a look at the TargetAction method.

Otherwise, check out this version of the script [gist.github.com] which outputs to text panels the same thing that is displayed in the terminal. It's untested though and I have no plans to support that modified version.

I haven't had a chance to play around with the Raycast stuff in the dev branch, but depending on how far cameras can scan, coincidence rangefinders (such as this script) may be obsolete. But I'll wait til it hits stable.
Manic 12 Dec, 2016 @ 6:46am 
This is complex, please teach my math class
Your Pal Deebs 11 Dec, 2016 @ 9:20pm 
How do I print out range on an lcd?
Manic 20 Apr, 2016 @ 8:06pm 
okay, That revenge will happen soon... bwahahahahahhaa
ZerothAngel  [author] 20 Apr, 2016 @ 7:54pm 
The coordinates are the same as GPS coordinates.

But if you want an actual GPS coordinate that appears in your list, you have to make the edit I mention above to RANGEFINDER_TARGET_FORMAT and then look at (or edit) the text panel after you get your range.

Unfortunately, that's the only way to pass GPS coordinates from scripts to players.
Manic 20 Apr, 2016 @ 7:49pm 
Before I use this, will it give me GPS coordinates? Is that possible? I have an orbital bombardment frigate and oneof my friends got me kind of mad so I need some accurate guided revenge...
ZerothAngel  [author] 2 Oct, 2015 @ 11:31am 
Thanks for letting me know. It should be fixed for the time being.