Space Engineers

Space Engineers

Gravity Flight System
80 Comments
OCD Insomniac 5 Apr, 2024 @ 5:58pm 
I added an event controller that switches the Artifical Mass and Gravity Gens off when Thrust% is <= 99 and this allows for use of Inertial Dampeners...but I have to have at least 6 thrusters to make use of it. I'd love to see a runable commands in the script that will enable/disable the dampeners..would be good for pwr efficiency and useful in other autopilot applications too.

Just finished a grav-drive build and I always use this script...but strangely, when I re-enable the dampeners, my ship turns around (torques) exactly 180 degrees...perfectly even. Weird but cool.

I've also noticed that the grav gens seem to cap at about 0.5G...not making full use of the available power. No idea if that is due to my build or if it's script related...I just noticed it. First time trying it on a build with a small grid grav gens mod.

I really hope you continue working on this script..I really do think it's the best I've found on the workshop. Thanks for this and I'll keep watch for updates!
Mata52 8 Jul, 2022 @ 5:06pm 
Then I am looking forward to any updates. Good luck and thank you for good content. :)
Tekk  [author] 8 Jul, 2022 @ 2:08pm 
First off: Thanks for the comment Mata52!
Secondly, from a recent project i did, I actually have some thoughts on fixing the offset forces, hovering in (moon) gravity and reducing the game workload, just need some free time to get into the project again (which i should have soon!)

If my ideas don't pan out, I will definitely look at what you mentioned, appreciate it :)
Mata52 8 Jul, 2022 @ 9:20am 
The script works flawlessly. The lack of the compensation feature is a drawback, though. I noticed that you said you might update the script, so maybe you will be interested in checking the "Jerry Rigged Torque Canceling Gravity Drive" that can be found on the workshop. The author retired but said that he would be happy if somebody continued his work and gave him credits for his contribution. He even claimed he would be glad to help with maths, if needed. In general, his script allows to completely nullify the unwanted torque generated by grav drives and allows to use that torque generation for turning your ship like with a gyroscope. The only problem is that his script for some reason impacts sim speed when used with very large ships, although I doubt its a matter of mass alone, after my multiple tests. Either way, you might want to give it a look. Maybe it could help you in figuring out the compensation mechanism, if you ever happen to want to improve this script.
Judge Kronos 17 Apr, 2022 @ 5:18pm 
This is my favorite Gravity script. I really like the PID that is at work ;)
Tekk  [author] 17 Apr, 2022 @ 3:44pm 
Cheers :)
Wouldn't say that I have gotten good, but i have gotten better and I am (slowly) updating my old scripts, so will get this fixed up eventually!
Judge Kronos 17 Apr, 2022 @ 3:15pm 
Thank you Tekk. If this was when you were worse looking forward to the one when you are good :p
Tekk  [author] 17 Apr, 2022 @ 1:54pm 
That's a warning, not an error; Unused variables don't really matter, apart from a warning message (and a couple of bytes of memory).

The script is super beta, and from when I was worse at C#, it grabs hold of the first IMyShipController it can find, so if you have multiple cockpit/seat/remote it may be selecting another. IIRC, Passenger Seats may also be picked up as IMyShipController.

A temp fix could be to replace:
GridTerminalSystem.GetBlocksOfType(cockpits);
on line 31
with:
cockpits.Add(GridTerminalSystem.GetBlockWithName("INSERT HELM NAME HERE") as IMyShipController;

That'll force it to use a specific controller.
Judge Kronos 17 Apr, 2022 @ 11:56am 
Your code has a compile error. It has 2 variables it does not use. so they need to be either deleted or commented out.

Vector3D LinVel, AngVel;

LinVel, AngVel are not used so you have to comment out as follows to use atm;

//Vector3D LinVel, AngVel;

Also I could not get the script to work with the Helm. Does the script search for Control blocks?
Tekk  [author] 7 Feb, 2022 @ 9:09am 
Ah yeah, totally forgot about adding that! IIRC, it is a bit janky, it gives a proportional response that will stop a vessel, but it will drift inside a planet/moon gravity. Building up the will (and look for the time) to go over my scripts and iron out the kinks haha
flaming_couches 6 Feb, 2022 @ 8:52pm 
Hey, great script! I noticed in the video you did showcasing it that you said there's a way to toggle inertia dampeners, and I managed to figure out that it uses the command argument "stab" by looking through the code. You might wanna post that as a tip on this page so that more people are aware you can do that (as well as any other configs that might be hidden that I didn't find)!

Also, despite the fact that gravity drives are a little pricey early-game in survival, I managed to build a small gravity-powered ship and it's really great! I'm definitely looking forward to saving on tight power resources while I go hunt down some uranium!
DickBandit 15 Apr, 2021 @ 8:52pm 
What is the best way to correct for torque, when the drives are seemingly built evenly around the center of mass?
Tekk  [author] 1 Feb, 2021 @ 6:09am 
4 points in the configuration specified.
I have a dream of making it dynamic during/after my Linear Control Design and Physics courses this semester, we'll see how it goes!
Gelnak 1 Feb, 2021 @ 5:38am 
Just curious, can this script be made to work with 8 points or can it only work with the 4 points?
DoableSnail 17 Jan, 2021 @ 12:11am 
I keep having a problem where the ship will roll slightly and angle up and down while moving. I get the error Program (239,25): Warning: The field "Program.AngVel" is not used AND Program (239,17): Warning: The field "Program.LinVel" is not used
ETHREAL1 11 Dec, 2020 @ 9:14pm 
Ya that’s what I though.... wish keen would just change how the autopilot works.... oh well dreams dashed
Tekk  [author] 11 Dec, 2020 @ 5:41pm 
Short answer: No on the autopilot.

Unless the autopilot is a mod that uses the cockpits actual control inputs, it won't work with this.
ETHREAL1 11 Dec, 2020 @ 2:46pm 
Question, I suspect I know the answer already as I suspect it’s that same as Vector thrust, but does this work with autopilot?
Tekk  [author] 22 Nov, 2020 @ 3:14am 
Well done figuring it out Bandit.
Not entirely sure why you were experiencing that issue, but i assume it has something to do, with how the script figures the center between the blocks, it may have thought that Mass blocks belonging to one group, belonged to another and tried to cover those with the grav field.

DickBandit 21 Nov, 2020 @ 7:30pm 
Update: The issue was the script grabbing other control type blocks, despite my making sure to build the primary cockpit first. The solution was to grind off the other control type blocks and reset the script. I rebuilt the program block for good measure. The script worked properly after that. I still don't know why the gravity ranges got configured in strange shapes when the script was using the wrong control block.
DickBandit 19 Nov, 2020 @ 10:52pm 
This script worked great when I set it up on a ship in creative and in survival single player. But when I built the same ship in multiplayer from the blueprint, the script no longer configures the grav gens correctly and I get no movement at all. HUD shows the grav fields all wrong; uniformly extended in directions that don't apply to the setup. I tried rebuilding the pg block and recompiling a fresh copy of the script. I can't tell what the problem is. Is this scrips known to work in multiplayer?
DickBandit 28 Sep, 2020 @ 11:36pm 
Thanks for the exclusion tag, Tekk. I'll give that a go.

@Zach, your request may be solved by simply grouping your grav gens and adding an on/off button for them to your G bar.
Zach 17 Sep, 2020 @ 1:26am 
Can you add to the script to turn off/on the grav drive blocks when not in use? would save some energy :D :energy:
Thomas 16 Sep, 2020 @ 11:55am 
I did but i had problems where is was using 2 flight seats, i think i just have too much going on for your script at times.
Tekk  [author] 16 Sep, 2020 @ 11:52am 
@Thomas Have you done a recompile on the script? (Should be done automatically, but still)
I just did a quick test and it's working fine on my end :|
Thomas 16 Sep, 2020 @ 4:59am 
My grav gens I have excluded, while not being changed get their Acceleration adjusted. "gravex" and gravex don't seem to work
Tekk  [author] 14 Sep, 2020 @ 9:42am 
Can't really tell without comparings the scripts. I'd wager on it being some sort of performance limit, my script isn't greatly optimized and it does a lot of stuff every tick
Tekk  [author] 13 Sep, 2020 @ 5:24am 
You can now exclude gravity generators from being controlled, by adding "gravex" to their custom data.
Tekk  [author] 13 Sep, 2020 @ 5:01am 
@Thomas
Hmm, did you recompile the script?
That error is what happens when they script is trying to use a block, without being linked to a block.

Might also be that your setup doesn't have the prerequisite 4 sets og gens&masses

@DickBandit

The script requires and can only utilize 4 sets og gens&masses, one in each of the 4 quadrants around the center of mass.

I'll update the script today to have a tag for excluding specific generators, i won't change anything else though (I have no time as of late :( ), so you'll have to make sure that the excluded generators doesn't mess with the mass blocks
Thomas 12 Sep, 2020 @ 3:31pm 
So after your past comment I have moved everything except now it simply will not work, it is almost like it doesn't see the grav gens and mass. None of the fields change when ran and I get this message.

Caught exception During execution of script:Object reference not set to an instance of an object.

Now im not sure what this means either.
DickBandit 4 Sep, 2020 @ 6:00pm 
Hi. Thanks for the great script.

Does the script only work with 4 quadrants of generators and mass at the 4 corners of the horizontal plane, or can I put them at all 4 corners of the front of the ship and all 4 corners of the back of the ship (for more balancing and power, given my space constraints at the center line)?

Is there yet a way to exclude gravity gens that are not part of the flight system? I have grav gens intended for a grav weapon that are being taken over by the flight script. Is there an exclusion tag or can I name them something else to trick the script into ignoring them?
Zach 2 Sep, 2020 @ 5:49am 
I'm about to try this out but with a diamond rather then your square..

lets see how good your scripting is! haha

_D_
DCD
_D_

vs your

D_D
_C_
D_D

Wish me luck :D
Tekk  [author] 31 Aug, 2020 @ 3:24pm 
That's a negative, as it stands i rekon you need a minimum of 16 gens to run this in a stable manner. The thing is, as opposed to thrusters, the force on the mass block is applied at the mass block. So if equal force isn't applied all the way around the center of mass, the ship will pitch/yaw/roll in an unintended manner when you're trying to move.

If the script was written for the purpose, and you built your ship specifically for it (6 grav gens in the center, with different orientations, and mass blocks symetrically around it) you could make a system work 6 gens, as long as the center of mass stays dead center of the system.
That seems to me, to be a pretty niche application though, not sure i'd be worth the coding time :|
GrayM3rc 31 Aug, 2020 @ 3:12pm 
is it possible to use this lets say with only 6 grav gens? playing on a server that limits the amount of grav gens one can have.
Tekk  [author] 31 Aug, 2020 @ 11:54am 
Well, the first things that catches my eye is that you say "both", the system requires four pairs of massblocks & grav gens :)

If that's not the problem, i think you have have placed the pairs too close together, or placed multiple pairs in one quadrant relative to the center of pass (eg. placing all 4 in front of / behind the center of mass)

If none of that applies to your problem, throw me another message :)
Thomas 30 Aug, 2020 @ 4:44pm 
On the vid, it showed it would only encompass the mass it is around but for me it covers both of my different chunks. Any idea why? If you need anything let me know
Tekk  [author] 20 Aug, 2020 @ 2:09am 
Well, a script really isn't supposed to be able to crash the game, the game is supposed to crash the script first.

May be something inherent with Gravity gens, creating an upper limit.
What that limit is, i can't say i'm afraid :|
Zen 19 Aug, 2020 @ 8:29pm 
This seems to crash the game every time I try to use it. Is there an upper limit to the number of gravity generators and mass blocks on a given grid? I am attempting to use it with a LOT of them.
[I.L]Methidox 19 Aug, 2020 @ 10:47am 
I love this! I can't wait to see how this advances
DEADPOO 6 Jul, 2020 @ 9:20pm 
That's sound great Tekk!

When you're in the pilot seat, you're still able to turn off Grav drive, right?

My ship has two flight mods. I use the Grav drive for fast hauling and lifting very heavy payloads off the moon. But, for preciseness like docking (which I really, really terrible at; I use SAM's autopilot and docking feature, unfortunately, that doesn't work with the Grav drive—I wish it would—so I switch over to Ion Engines).
Tekk  [author] 6 Jul, 2020 @ 8:01pm 
I can do you one better, i can make the script check if the pilot seat is occupied, and automatically only have the drive on when it is.

Brilliant idea DEADPOO, really hadn't thought of doing that.

When i have a minute i'll make it so you can tag a Grav gen in Custom Data, when a pilot is in the seat that Grav gen will be off and the grav drive will be on, when there is no pilot then that grav gen will be on and the drive will be off.
DEADPOO 6 Jul, 2020 @ 12:42pm 
Put up a Sensor to detect when you're on the ship. In the home state have it trigger the TB. Now, I know what you're thinking but if the Sensor turns off the Gravity drive how will I fly the ship??? Well, yes while you're on the ship and walking about, the Gravity drive will be turned off but as soon as you get in a Flight/Control Seat the weirdness that is SE doesn't detect you anymore. So you can turn the Grav drive back on in your hot-bar to fly and it won't shut down. As soon as you hop out of the seat, the grav drv automatically turns off and you have internal gravity.

If anyone wants to see my setup let me know and I'll put it up.
DEADPOO 6 Jul, 2020 @ 12:42pm 
Here's my workaround for having internal gravity. What you need:
1 Timer Block
1 Programable block (for the script: MoveIT)
1 Sensor
1 Gravity Generator (You could build a separate one, but that's a waste; you have like 70+ already, so pick one. I picked the closet grav.)

I grouped everything related to the Gravity Flight and named it GravitySys. That means PB GravFlight, Mass blocks, and the Gravity gens (except for the 1 isolated). This is so you can toggle them ON/OFF.

In the TB set it up so GravitySys OFF, IntGravity ON, and have it run the MoveIT PB (Here's my setting: "IntGravity" +9 Depth 55 Height 30 Width 50)
DEADPOO 27 Jun, 2020 @ 5:56pm 
Great fix on designating the controller seat, Tekk.

Now...is there any way to isolate a gravity generator from the Flight system? Like you only want to use it for interior gravity so you can walk around. Maybe put an exception symbol in the name so the script knows to skip it?
BOFH 21 Jun, 2020 @ 8:56am 
Tag option to exclude drives would be great. I use a grav gen to force scrap into a collector from my railgun, it has a very tight small field to just do one job so doesnt reach the mass blocks.
Terminids' Bear Grylls 25 May, 2020 @ 6:20am 
Nice script, you may want to underline the fact that the force of a gravity drive scales with the product of grav gens and artificial masses, therefore while 1 grav gen and 1 mass give the power of 1.5 engines, 5 grav gen and 5 masses (all in the fields of the 5 grav gens) generate 25 times this amount of force while requiring only 5 times the amount of power and mass, and so on, being therefore more mass and energy efficient the bigger the engine is.
Tekk  [author] 10 May, 2020 @ 4:43am 
Ahhh
Yes, that's the place. Keep in mind that it is Case and space sensitive.
It should work, at least it did on the few tests i did

Desk chairs and beds should not register as flight controllers, but i guess keen half-arsed the cosmetics a bit, i will have to keep that in mind when i do an overhaul

H1Z1 BLOWS 9 May, 2020 @ 10:02pm 
Ok I got an update... for adding the main seat to controls?? do you mean example: string ControllerName = "";//Enter the name of your main cockpit between the "Flight Seat 1" ??
I discovered that if i get into one of the beds on board i have control of the gravity drive... so i deleted all beds... then i found a desk chair that was now the control of the drive... so i ended up deleting all couches, desk chairs, toilets and beds... anything i could sit on... started with a single flight seat again and holly cow it works... im able to put the beds and chairs back now but if i recompile i will have to delete all the stuff again... I still think i didn't put the name of main seat in the right spot of the script.
H1Z1 BLOWS 9 May, 2020 @ 6:22pm 
I'm still stumped... Not sure whats going on... I know the drives are working cuz it holds the ship in place even if i go forward on the thrusters... Tried turning it off and on with no luck... is there a limit to this script? Meaning is there a max distance the quadrants can be form each other? Or maybe a PCU or block limit? The weird thing is the original flight seat and program block that i saved a week ago works great but need to move the seat and program block to inside the ship... As soon as i delete the original seat or program block i cant get it to work again... The distance from center of front quadrants to the back is 59 blocks... i really appreciate you trying to help me out.
Tekk  [author] 9 May, 2020 @ 2:13pm 
I have updated the script, added a line at the top where you can input the name of the cockpit/remote you want in control :)

If you're even stuck again, try turning your ship off and on again, no joke, when i've modified my test crafts i sometimes had to do that. I think it's an SE physics quirk.