Space Engineers

Space Engineers

View Stats:
clop1000 Oct 1, 2023 @ 11:04pm
How to write a simple script to measure distance to an asteroid?
How to write a simple script to measure distance to an asteroid?
< >
Showing 1-14 of 14 comments
ShadedMJ Oct 2, 2023 @ 2:07am 
You don't. Think about how you are going to measure that distance or really any distance in the game. You can't unless you get there and put down a GPS coordinate. You can't even know your own location without a GPS or using a script.

That said... What I did in the beginning was set up a grid with 2 cameras far apart each pointed at a specific point on the asteroid. Then use algebra and I could get close enough for my needs. Now its done using camera raycast which doesn't measure the distance to the asteroid, just tells you the asteroid location and using algebra to distance from your own location.
So... a simple script....
MyDetectedEntityInfo INF=Camera.Raycast(range);
double DISTANCE=(INF.HitPosition.Value-Me.GetPosition()).Length();
Rox Oct 2, 2023 @ 2:20am 
Lets step back here... why do you want to know the distance to an asteroid, what limits in terms of shortest and longest distance are you hoping to achieve, and to what level of accuracy ? ... and is this from a small or large ship ?
Last edited by Rox; Oct 2, 2023 @ 2:21am
Valen Oct 2, 2023 @ 2:42am 
Well, not sure what the OP intentions are with it. But it could be usefull to decide at what moment you need to engage your thrusters to do a suicide burn. (or pointed just enough away from it and not overshoot it)
Last edited by Valen; Oct 2, 2023 @ 2:42am
Rox Oct 2, 2023 @ 2:48am 
Originally posted by Valen:
... could be useful ...

Indeed it could be useful for many things, including just identifying the closest asteroid to the current ship position, for whatever reason... but depending on the situation and reason, there could be alternative sources of information that could be equally useful.
ShadedMJ Oct 2, 2023 @ 2:58am 
Since I write scripts and have a math background, I use raycast to get the location of the asteroid, get the vector and distance to asteroid, trim 100m or so off the distance, put that as a destination for remote control, let it go, and it stops about 100m from the asteroid.
I admit I was a little harsh with OP, but the opening question sounded like it was from someone who didn't know scripts or math, and its a requirement to know that.
Last edited by ShadedMJ; Oct 2, 2023 @ 3:00am
UbioZur Oct 2, 2023 @ 3:18am 
It would depends on your definition of simple. and your dev environment and your scripting experience.

You use the camera ray cast api https://forum.keenswh.com/threads/new-camera-raycast-and-sensor-api-update-01-162-dev.7389290/

- You select the camera you want to use.
- Check the camera can use the raycast.
- Use the Raycast function on the block
- Check the return value to see if it detected something in the given distance
- If detected, check the type of the detected object to be an asteroid.
- If asteroid Calculate the distance between your position and and the object position.
- Do something with with the distance you calculated.

You can also look at the outdated wiki https://www.spaceengineerswiki.com/API:Sandbox.ModAPI.Ingame.IMyCameraBlock (why would keen has an wiki to not update it...

Or the very outdated Open Source as doc
https://github.com/KeenSoftwareHouse/SpaceEngineers
But again why would keen keep it updated to help coders...

Best option is to actually install the MDK toolkit https://github.com/malware-dev/MDK-SE for visual studio
Or the one for VS Code https://github.com/gregretkowski/VSC-SE
As the intellisence will give you much much much better up to date and accurate information on what functions and classes are available to you and what they can do.


EDIT: You can also learn by reverse engineering those scripts (I haven't tested them):
https://steamcommunity.com/sharedfiles/filedetails/?id=3029899210&searchtext=distance+to+asteroid
https://steamcommunity.com/sharedfiles/filedetails/?id=532272288
https://steamcommunity.com/sharedfiles/filedetails/?id=1536579969&searchtext=range+finder
https://steamcommunity.com/sharedfiles/filedetails/?id=823520451&searchtext=range+finder
Last edited by UbioZur; Oct 2, 2023 @ 3:22am
Valen Oct 2, 2023 @ 3:28am 
Camera detected amounts of sarcasm in the previous message. ;)
UbioZur Oct 2, 2023 @ 3:31am 
Originally posted by Valen:
Camera detected amounts of sarcasm in the previous message. ;)
Especially in the documentation provided by keen part...
Rox Oct 2, 2023 @ 3:37am 
There is no evidence that Keen have ever used or created any documentation of any kind, there is only hearsay and conjecture.
Just a thought, unless Malware (user name) has updated his Visual Studio plug-in, it only works on VS2019.
simu Oct 2, 2023 @ 11:38am 
Originally posted by Ronin Planetary Industries (RPI):
Just a thought, unless Malware (user name) has updated his Visual Studio plug-in, it only works on VS2019.

Visual Studio 2022 since May,,,
Buckshot Oct 2, 2023 @ 12:10pm 
Originally posted by clop1000:
How to write a simple script to measure distance to an asteroid?
Great thread.
There really isnt a way to measure distances in SE unless you have GPS points set. This, IMO, is a huge downfall in SE. This game is getting old and it shows. Now, in the 21st century, there are things call lasers that can measure distances. Under water, it is called sonar. I guess when SE was designed and developed, lasers and sonar were not a thing yet? IMO the devs of SE need to get caught up with real technologies and simulate those in this game. Come on Keen...get caught up to the 21st century :)
Rox Oct 2, 2023 @ 12:42pm 
I was using a portable laser distance measuring device in 1994... and SE was in on Steam in 2013... but, it's a game, and distance was not important in it's beginnings, when the main idea was to make space LEGO-like ships and smash them against each other.
ShadedMJ Oct 2, 2023 @ 1:53pm 
Originally posted by Buckshot:
... Come on Keen...
I actually think that the missing information is intentional and there are times where I agree with it. If you could pull the target information out of the ore detectors and antenna, the game turns into Automation Engineers and players who write scripts will run the show and non-scripters get left in the dust. I think developers want the player to actually look for ore and actually explore the asteroids.
< >
Showing 1-14 of 14 comments
Per page: 1530 50

Date Posted: Oct 1, 2023 @ 11:04pm
Posts: 14