Space Engineers

Space Engineers

View Stats:
Auto-Ascent-to-Space Script
I've found the greatest challenge of flying from a planet's (or moon's) surface to space is conserving hydrogen to the greatest extent possible. There are currently a few ascent scripts available for carrying out this process, but they seem to be all-or-nothing script, i.e., slamming the ascent thrusters, whether bottom or rear, to full power until outside the planet's (or moon's) gravity well, then kicking the power output back to normal.

After years of designing ships with "up" thrusters assigned in "banks" so no-longer-necessary banks of thrusters can be disabled while ascending to space, I've found that using the "up" thruster's "increase thrust override" and "decrease thrust override" features to be much more efficient for the ascent phase for conserving hydrogen.

Alas, I'm just an old fart who hasn't yet mastered the script-writing process. Can someone develop a script that will simply push the grouped "up" thrusters to maximum thrust override and incrementally decrease the thrust override as gravity diminishes? Perhaps the script could have a flag that would use either the bottom "up" thrusters or rear "forward" thrusters for the ascent, as selected by the user?

I envision the script would increment thrust override downward one step, check the rate of deceleration and, if too high, increment thrust override upward one step, wait for a short amount of time (5 seconds? 10 seconds? 15 seconds? Let the user decide?), then try again. This process would continue until out of the gravity well whereupon thrust override would be disabled thereby allowing the ship to coast to a stop. An automated process like this would potentially minimize hydrogen consumption and make for a much better space run.

Anybody interested in helping an old guy?
< >
Showing 1-15 of 25 comments
Uhm.....This may or may not fit your criteria...
I write scripts and have a ship that goes from earth to space without thrusters. No hydrogen used. The ride can be labeled "hold on to your butts" if the system isn't calibrated (script).
Interested?
You bet. I'm intrigued about how to get from earth to space without thrusters.
I'll probably do a world save or workshop thing this weekend. Fairly busy though.

On the flip side, I had this solved enough for my tastes a while ago as a manual process, and would now make a script to duplicate it. I'll state it here for peer review, or if someone else wants to try a script for it.

Hydrogen thrusters off, go up as high as atmospheric/ion allows, at this point upward velocity is nearly 0 m/s, activate hydrogen thrusters on override of 1% or whatever through ship toolbar, keep increasing hydrogen thruster override until 90-95 m/s reached, 100 m/s will be wasting hydrogen, will have to decrease thrust override with ship toolbar the further up you go because gravity will decrease and velocity increase, and then space.
You're amazing with scripts, ShadedMJ and this game. If it's posted for everyone it will probably get tested and used by many.
Going through final debugging, but had a bunch of schtuff to say. I also have puppy care that has priority. Script posting shortly.

1) Of course, I'll maintain this, but I am going to be picky about who to support. I can easily see someone pulling this and using it in the wrong conditions and complaining about it. Stuff like saying it doesn't get to space when there weren't enough thrusters in the first place and stuff like that.

2) Script works for my test case. 53000 kg ship. Only tested on earth-like in creative so far. It should work on other planets in theory.

3) Thrusters..... Y'know, in scripts I can't tell the difference in thrusters, so hydrogen thrusters have to have the word 'hydrogen' in the block name. From earth-like and having a ship with atmospheric _and_ ion thrusters, the whole plan goes weird.

4) Criteria was to conserve hydrogen.

Short summary of the process:
(This was edited after I changed the code a bit)
Maybe modify the first line of the script to say what cockpit name is used, but if you don't I'll try to find it.
Try to get the ship level.
Run the programmable block with "ASCEND".
Running the programmable block with "ABORT" will reset everything.
Non-Hydrogen lift thrusters will be override at 100%.
There will be a 3.2 second delay here.
Hydrogen thrusters lift thrusters will be override at 100%.
Ship should speed up and hover between 80 and 90 m/s,
This continues until space is reached.
When gravity goes to zero, all overrides removed and script is in idle state.
string CockpitName=""; // Put cockpit name here, otherwise I'll try to find one
//=============================================================
public IMyCockpit CockpitReference=null;
public int State=0; // 1=Low Altitude Setup, 2=Low Altitude Flight
// 3=High Altitude Setup, 4=High Altitude Flight, 5=Space Setup, 6=Abort
public int SubState=0; // Used as a timer
Base6Directions.Direction Direction;
public Program() {
// Run Main() 6 times per second
Runtime.UpdateFrequency=UpdateFrequency.Update10; }
public void Save() { }
public string ErrorMessage="";
public void Main(string argument, UpdateType updateSource) {

// Diagnostics to a LCD screen for testing. This section can be removed.
IMyTextPanel TP=GridTerminalSystem.GetBlockWithName("Monitor Panel") as IMyTextPanel;
if (TP!=null) {
TP.WriteText("");
if (CockpitReference!=null) {
TP.WriteText("Speed "+CockpitReference.GetShipSpeed().ToString("0.0")+"\n",true);
TP.WriteText("Grav "+CockpitReference.GetNaturalGravity().Length().ToString("0.0")+"\n",true);
double Elev;
CockpitReference.TryGetPlanetElevation(MyPlanetElevation.Surface,out Elev);
TP.WriteText("Elev "+Elev.ToString("0.0")+"\n",true);
IMyThrust Thr=GridTerminalSystem.GetBlockWithName("Large Hydrogen Thruster") as IMyThrust;
if (Thr!=null)
TP.WriteText("H Thrust Over "+Thr.ThrustOverridePercentage.ToString("0.0")+"\n",true); } }

if (argument=="ABORT") {
State=6; }
if (argument=="ASCEND") { // Start or abort ascend
if (State!=0) // Cancel
State=6;
// Start ascend
else State=1; }
if (updateSource==UpdateType.Update10) { // This runs 6 times per second
if (State==0) Echo(Idle()+"\n LastMsg : "+ErrorMessage);
if (State==1) Echo(StartLowAltAscend()+"\n LastMsg : "+ErrorMessage);
if (State==2) Echo(LowAltAscend()+"\n LastMsg : "+ErrorMessage);
if (State==3) Echo(StartHighAltAscend()+"\n LastMsg : "+ErrorMessage);
if (State==4) Echo(HighAltAscend()+"\n LastMsg : "+ErrorMessage);
if (State==5) Echo(StartSpace()+"\n LastMsg : "+ErrorMessage);
if (State==6) Echo(Abort()+"\n LastMsg : "+ErrorMessage); } }
string Idle() {
return "Idle"; }
string StartLowAltAscend() {
string Msg="Starting Low Alt Ascend";
// Find cockpit and abort if not found
FindCockpit(out ErrorMessage);
if (CockpitReference==null) {
State=6; // Abort
return Msg; }
// Find gravity and orientation needed
Vector3D GravityVector=CockpitReference.GetNaturalGravity();
Direction=CockpitReference.WorldMatrix.GetClosestDirection(GravityVector);
// Get list of thrusters
List<IMyTerminalBlock> BlockList=new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyThrust>(BlockList);
// Up thrusters atmospheric and ion at full override. All hydrogen off.
foreach (IMyThrust Thruster in BlockList) {
if (Thruster.CustomName.Contains("Hydrogen"))
Thruster.ApplyAction("OnOff_On");
else if (Thruster.Orientation.Forward==CockpitReference.Orientation.TransformDirection(Direction)) {
Thruster.ThrustOverridePercentage=1; } }
SubState=20;
State=2; // Ascend
return Msg; }
string LowAltAscend() {
// Wait 1.6 seconds for atmospheric and ion thrusters to hit full override
if (SubState>0)
SubState--;
if (SubState==0) {
// If going slow, shift to Hydrogen
if (CockpitReference.GetShipSpeed()<20)
State=3; }
return "Low Altitude Ascend"; }
string StartHighAltAscend() {
string Msg="Starting High Alt Ascend";
// Find cockpit and abort if not found
if (CockpitReference==null) {
FindCockpit(out ErrorMessage);
// Find gravity and orientation needed
Vector3D GravityVector=CockpitReference.GetNaturalGravity();
Direction=CockpitReference.WorldMatrix.GetClosestDirection(GravityVector); }
if (CockpitReference==null) {
State=6; // Abort
return Msg; }
// Get list of thrusters
List<IMyTerminalBlock> BlockList=new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyThrust>(BlockList);
// Up hydrogen thrusters override at 50%
foreach (IMyThrust Thruster in BlockList) {
if (Thruster.CustomName.Contains("Hydrogen")) {
if (Thruster.Orientation.Forward==CockpitReference.Orientation.TransformDirection(Direction)) {
Thruster.ApplyAction("OnOff_On");
Thruster.ThrustOverridePercentage=.5f; } } }
State=4; // Ascend
return Msg; }
string HighAltAscend() {
string Msg="High Alt Ascend";
// If outside of gravity, reset and done
Vector3D GravityVector=CockpitReference.GetNaturalGravity();
if (GravityVector.Length()==0) {
State=5;
return Msg; }
// Get ship speed
double Speed=CockpitReference.GetShipSpeed();
// Get list of thrusters
List<IMyTerminalBlock> BlockList=new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyThrust>(BlockList, b => b.CubeGrid==Me.CubeGrid);
// Up thrusters : Hydrogen override +- 1% hovering at speed 98 m/s
foreach (IMyThrust Thruster in BlockList) {
if (Thruster.Orientation.Forward==CockpitReference.Orientation.TransformDirection(Direction))
if (Thruster.CustomName.Contains("Hydrogen")) {
if (Speed>90)
Thruster.ThrustOverridePercentage-=00.1f;
if (Speed<80)
Thruster.ThrustOverridePercentage+=00.1f; } }
return Msg; }
string StartSpace() {
// Get list of thrusters
List<IMyTerminalBlock> BlockList=new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyThrust>(BlockList, b => b.CubeGrid==Me.CubeGrid);
// All thrusters : On & Override off
foreach (IMyThrust Thruster in BlockList) {
Thruster.ApplyAction("OnOff_On");
Thruster.ThrustOverride=0f; }
return "In Space"; }
string Abort() {
// Reset & Remove all thrust overrides
//CockpitReference=null;
List<IMyTerminalBlock> BlockList=new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyThrust>(BlockList, b => b.CubeGrid==Me.CubeGrid);
foreach (IMyThrust Thruster in BlockList) {
Thruster.ApplyAction("OnOff_On");
Thruster.ThrustOverride=0; }
ErrorMessage="Aborting & "+ErrorMessage;
State=0;
SubState=0;
return "Aborting"; }
void FindCockpit(out string ErrorMessage) {
ErrorMessage="";
if (CockpitName!="") { // Find cockpit by name and deal with potential problems
IMyTerminalBlock Block=GridTerminalSystem.GetBlockWithName(CockpitName);
if (Block==null) {
ErrorMessage="Problem : Cannot find cockpit "+CockpitName; }
try {
CockpitReference=Block as IMyCockpit;
return; }
catch (InvalidCastException) {
ErrorMessage="Problem : "+CockpitName+" is not a cockpit";
return; } }
else { // Search for cockpit
List<IMyTerminalBlock> BlockList=new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyShipController>(BlockList);
if (BlockList.Count==0) { // No cockpits.....
ErrorMessage="Problem : Cannot find any cockpit type block";
return; }
if (BlockList.Count==1) { // Found 1 so that must be it
CockpitReference=BlockList.ToArray()[0] as IMyCockpit;
return; }
// Found multiple cockpits. Find main one.
foreach (IMyShipController Block in BlockList)
if (Block.IsMainCockpit) {
CockpitReference=Block as IMyCockpit;
return; }
// More than one cockpit but none are main
ErrorMessage="Problem : Cannot find main of many cockpits"; } }
Thank you for doing this.

I tried it on my ship, a heavy-lift small-grid concept that I want to use for colonizing a planet and/or as a freighter. It has a mix of small and large hydrogen thrusters as well as a few small atmospheric thrusters to help with lift.

I assigned the programmable block to my cockpit controls, using "ASCEND" for the argument. I also put the cockpit name in the script, as instructed. Finally, I loaded the ship to its maximum capacity, filling all cargo containers, connectors, and the cockpit with steel plates.

I manually flew the ship up for a bit, then stopped and let it hover. Then I hit the assigned key and all thrusters turned off and the ship began falling. I hit the assigned key again and all thrusters turned back on, but the ship just slowed to a stop, then hovered there without ascending.

What did I do wrong?
This is my script, there is a constant for the speed.. Thrusters will not power to exceed that speed works in any direction.

Edit removed script : lots of scrolling lol..

Edited again: i uploaded it .. https://steamcommunity.com/sharedfiles/filedetails/?id=2653910012
Not Exactly what you ask for but does save power waste and makes leaving planets for me worry free
Okay... Are you using hydrogen thrusters on the ship for hauling that around?
Ascend shuts off the hydrogen thrusters while the ship goes to high altitude.
If this is the case, I can probably adjust, but kind of blows the criteria for conservation of hydrogen.

Edit: @Mollymawk : Did you <spoiler> that code? Doesn't show on my screen unless hovering over it, making it look like a big empty. I am not sure if your code is a companion or competition for what I wrote, but I'm very cool with it either way. :) Whatever works.
My Script is just what I use . i wrote it a very long time ago... No competing intended.. i've removed it, as you say , probably as many versions as script writers, spiff only needs one :-)

I thought spoiler would fold it, it didn't, looked a mess and wasn't helpful, I'm ashamed :-) i just wanted to avoid people scrolling through code of the forum, tiss never nice to see

edit: And i had it loaded in the ship im using right now , hence the ill conceived cut paste :-)
I was just trying to go straight up to space; the lift thrusters are bottom-oriented, i.e., I ascend with the ship level to the horizon. I thought I understood that the ASCEND command shuts off all hydrogen thrusters except the lift thrusters, but everything shut off.
1) Start on a flat surface aligned to the planet's gravity or you'll waste fuel climbing at an angle.
2) Set all the thrusters going up into a group.
3) Hotkey increase thrust override and decrease thrust override
2) Lock your gyros
3) Slowly increase thrust until you ascend
4) Use the hotkeys to maintain a speed near but not quite full speed.
5) As gravity decreases you can decrease thrust over and over until you leave gravity.

It's not perfect, but this is the most fuel efficient way of doing it that I've found without using a script. If you've got speed mods, things change. Figure out what speed you need to be carried by the ships momentum - usually 500-600 m/s for my builds. Burn fuel til you hit that then let inertia do the rest.

I should make a mod that consists only of a 1km long armor block that only attaches to other blocks at the ends to make space elevators possible.
With the exception of locking gyros, I've used thrust override for the "up" thrusters to conserve fuel manually. It works well, but I was hoping for an automated process that would continually dial down thrust override as the ship ascends to higher altitudes, eventually disabling thrust override after exiting the planet's gravity well.
In my games, I only used dropship designs (straight up, straight down) for cargo to space and back.
I mentioned I only tested in a tiny ship. I'll see how it handles something bigger. I will be delayed though, as I have a sick puppy in my office, and wife in panic puppy mode.
No problem. I'm not in any hurry. Thanks, and I hope your pup recovers quickly.
< >
Showing 1-15 of 25 comments
Per page: 1530 50

Date Posted: Nov 11, 2021 @ 6:36pm
Posts: 25