Space Engineers

Space Engineers

3-Axis Gravity Drive v2.0
39 Comments
Rizzo 20 Jun, 2021 @ 4:14pm 
I was using this script for quite some time, but it appears bugged after recent updates. There are a lot of warnings in the script now and the two ships I had this on had issues with thrusting and thrusters being turned off by the script.
sHanQ 17 Aug, 2017 @ 8:29am 
alright, thanks mate!
BurninSun  [author] 17 Aug, 2017 @ 7:54am 
The tagging does not work on groups, so that may be the issue - I never tested how the script reacts to not having a certain component working and in this case it wouldn't have the mass blocks.

That said, there should be a MUCH simpler script available these days as I'm pretty sure they finally exposed the thruster force property to the in game programming API. That would cut the meat of the script down to about 6 lines of code. As I haven't playing in years, I'd suggest looking for an alternative script.
sHanQ 16 Aug, 2017 @ 11:57pm 
o/ hey

had the same idea for a script too, googled for it and found yours.. good job as far as i can tell, got a little problem

i have everything setup just the way you listed it above... i've named everything like this: http://i.imgur.com/aODRK7x.png (hope the group of mass blocks is fine this way)

unfortunately the gravity generators turn off upon running the script and never turn on again. they are not mirroring the thrusters at all

any clue what the issue might be?
BurninSun  [author] 14 Apr, 2017 @ 10:50pm 
Is it actually broken or just giving "obsolete" errors? I don't intend to do much fixing when there is new API that has been sitting on the experimental branch for over a year now that would reduce this script to just a couple lines of code. So if its just the obsolete error, just ignore it until if/when they decide to push the API changes live.
E-Man720 14 Apr, 2017 @ 7:47am 
Is there any ideas where this is at now? Or if theres a fixed variant?
BurninSun  [author] 24 Feb, 2017 @ 7:50pm 
The SE devs streamlined their API a bit meaning old function calls will be removed from the game at some point. The obsolete thing is just a warning to update to the new calls so they can be safely ignored for the moment. For this script in particular though, they have been working on new features that would make the majority of this code obsolete in favor of something much simpler. So I probably won't fix this just because when those new features go live (which are currently working in the experimental branch) I would think someone else would put out a revised script that accomplishes the same thing this one does with much less code.
Copycat80 21 Feb, 2017 @ 2:20pm 
whenever I check the code, it gives me multiple arguments that are "obsolete" can you fix them , or is the problem on my end?
BurninSun  [author] 5 Feb, 2017 @ 11:18pm 
Using things like autopilot or getting coordinates based on direction don't work because there is no way to tell the difference between unwated drift and the pilot purposefully rotating the ship.

There is (as far as I know) no easy way to get the moment of inertia for a ship. So there is no way to calculate torque which would then be easy to correct with gyros.

That said, it would be possible to use "orphan" gravity drives that don't overlap the base drive placed on the extremes of each of the 3 axis (only 1 set needed per axis due to being able to set both positive and negative gravity). Then for each axis, calculate the location of the acceleration axis from the base gravity drive components then calculate the strength needed on the orphan drive to bring that acceleration axis in line with the center of mass of the ship. All of that could be done on script initialization if you don't need to take into account adjustments due to ship damage or cargo loads.
Metavamp 3 Feb, 2017 @ 1:58pm 
Any ideas on a way to balance a ship's center of mass using 4 grav ball drives? Maybe auto pilot compensation could be used, if one could make a camera lase a gps point in the distance to follow, and then adjust grav ball mass from that. Might get it close. Great script!
BurninSun  [author] 27 Jan, 2017 @ 10:49pm 
For setup, check the example ships to get an idea of the "core". There isn't too much to it except to have at least 1 thruster in each direction somewhere on the ship, then your mass blocks roughly centered around your center of mass.

IMHO, spaceballs are overkill since this setup is so power and space efficient compared to thrusters to begin with. I can already fly a massively overweight factory ship off solar panels and batteries as it is. Spaceballs do allow adjustments in virtual mass though which could be useful to finely adjust the gravity acceleration vector to match the ships center of mass and remove the drift caused by off center gravity drives.
Spanker 26 Jan, 2017 @ 12:35am 
thank you for this help burninsun : was working on self aware drones actually but i will look into it now . (success for self aware drones , working on planets and seeking enemies far away (40 km radius ) without raycast ...
ill publish this one if u want , already published the "rough" versions

maybe then i will use spaceballs ( less efficient but powerless )
thanks !
Kalsaphix 24 Jan, 2017 @ 3:48pm 
question? can we get a better describtion on how to best set this scrip up? I would like to set it up in a rather large ship, I wanna do it right the first time.
BurninSun  [author] 15 Jan, 2017 @ 10:32am 
With the alignment, not only do you have to worry about getting the acceleration vector lined up with the center of mass, but with sphericals, you have to worry about the acceleration vector actually being lined up with a cardinal direction. Not so bad if everything is built symetrically.

To modify this code, I would imagine manually tagging (or grouping) mass blocks by direction they represent, getting those groups within the Init function, then change out the lower part of Main to turn your mass block groups on/off instead of the gravity generators.

You would lose dampener control as you only have one set of gravity generators and cannot adjust the mass block's mass. You'd also have to strip out the code for finding the various components and setting the field strengths.
Spanker 14 Jan, 2017 @ 12:42am 
yeah , actually all my ships have linear for weapon , spherical for prop ..

what do you mean "work with correct alignement" ? inertia distribution ? i find it easier to fix it on sphericals ...
ima try to code something crude : get consumption , fire corresponding axis mass .. i dont really need dampeners :D
BurninSun  [author] 13 Jan, 2017 @ 1:52pm 
It would be doable but outside of the scope I would want to write up. You would need to define groups of mass blocks by direction manually then turn on/off the appropriate groups instead of turning on the gravity. Getting sphericals to work with correct alignment is not easy though.
Spanker 13 Jan, 2017 @ 1:33pm 
Hello there , is there a way to activate masses instead of gens ? so i can use my sphericals in negative gravity instead of linear grav gens ?
BurninSun  [author] 4 Jan, 2017 @ 11:21pm 
Offgrid PB support would be possible by modifying the code to choose an arbirary block that is on the same grid as the gravity drive components (eg. just choose the first gravity generator) and replace all instances of Me.CubeGrid with MyArbitrary.CubeGrid. Only potential issues are that you won't be able to dock with another gravity driven ship that uses the same name tags, and all other gravity drive components still need to be on the same subgrid as each other.
Witchhunter Captain 4 Jan, 2017 @ 9:28pm 
Does not support multigrid, sadly. Works only if you put a programmable block on the same sub-grid as the gravity drive components.
eRaz0rHead 26 Oct, 2016 @ 1:43pm 
No problem -- I don't see any issues either, so I was merely asking out of curiosity. I've only recently come back after a hiatus myself. Thanks again for your work on this script.
BurninSun  [author] 26 Oct, 2016 @ 11:47am 
As I've taken a hiatus from the game again and the fact that the new API should make it super simple, I doubt it. But doing a bit of reading, I'm not sure the new API I was thinking of is actually released yet. It may still be dev branch only. If there are any outstanding bugs that can be well defined, I'd be willing to take a look to try to fix, but at this point, I don't see making any major updates and in my testing, I saw no major issues.
eRaz0rHead 22 Oct, 2016 @ 12:22pm 
@BurninSun Do you think you'll do a version 3 with the new API ?
BurninSun  [author] 22 Oct, 2016 @ 10:31am 
As a followup to the questions here... I've abandoned this script as there has been API changes that should make this same functionality MUCH simpler to program (one can ask the API for the thrusters current output directly instead of doing the cycling as this script does).

The oscillations issue has some code to help combat it, but is impossible to fix completely. (although it may be possible now with the API changes). Esentially, the problem is too large of a drive on too small of a ship. Try adjusting the StopSpeed variable to something larger.
eRaz0rHead 21 Sep, 2016 @ 3:06pm 
@Copycat80
Does hitting "Reset" help with the oscillation ?
I found that the closer the grav drive was to center of mass, the better the performance of the whole ship.

I also wonder if the percentage of total ship mass the artificial mass takes up might affect the performance.

Copycat80 17 Sep, 2016 @ 9:03am 
my Gravity drive over-compensates and creates an ocellation that makes moving about on my ship impossible,is there a way the grav drive be made less sensitive to the thrusters dampeners so my regular thrutres can stabilise my ship?
eRaz0rHead 13 Sep, 2016 @ 8:26am 
Love this script.
I tested it with an "off center" small ship (just to see how capable it is), and it still worked somewhat -- there were some issues where it would veer off center (as expected) and get stuck in an "on" mode even when the dampeners were firing. Sometimes it would jitter back and forth when stationary, which was very funny to watch.

All of those issues disappeared when I moved the center of mass in-line with the direction of travel.

I'm planning on incorporating it in a larger ship design soon.
Copycat80 8 Sep, 2016 @ 1:00pm 
can I adjust the gravity width to eliminate it from messing with my on-ship gravity, or will it just find all the mass blocks by increasing the range automatically?
Copycat80 8 Sep, 2016 @ 6:54am 
stable compatable?
MerlinCheater 19 Aug, 2016 @ 7:36am 
not working can you fix it plise!!! Wery Plise!
BurninSun  [author] 13 Jul, 2016 @ 3:39pm 
Glad it worked for you. The goal was to be able to move these types of massive ships without having to cover them in thrusters. Now if only someone would contribute the math to have gravity generator assisted gyros...
laci4321 (HUN) 13 Jul, 2016 @ 3:08pm 
I am glad that you have decided to updgrade this script! With this gravity driving method, there is no limit in mass of the ship. I used in my ship, thank you very much BurninSun!
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=723855022
TMF Muffinman 2 Jul, 2016 @ 9:57am 
I appreciate your work here. I was looking for an updated version of this system for a long time.
BurninSun  [author] 1 Jul, 2016 @ 6:03pm 
Strange, I don't know what would cause that. No matter what, a "reset" should reset everything, and docking/undocking is detected even after the pb is turned off and back on. Glad it's fixed.
E-Man720 1 Jul, 2016 @ 5:38pm 
Ok for some reason, somehow, a world reload fixed it.
E-Man720 1 Jul, 2016 @ 5:26pm 
It was on a frigate, but I shut down the drive before I docked it. But when I undocked it and tried to switch it back on the drive refused to run. Even after deleting the script out of the PB and reinstalling it. And SP using small reactors and no solar.
BurninSun  [author] 1 Jul, 2016 @ 5:19pm 
Does it work again after a "reset"? If it can't get correct readings from power sources, it would cause it to act like you described. Solar panels on dedicated servers are still having issues reporting power correctly as far as I'm aware, are you on a dedicated and using solars? Or any modded power sources? Also, I forgot to account for connections/dockings via rotors so if you attach another ship via a rotor, it won't auto detect and would require a "reset" for that as well.
E-Man720 1 Jul, 2016 @ 5:03pm 
I tried that, it cycles the thrusters like normal, but just never switches the drive on.
BurninSun  [author] 1 Jul, 2016 @ 5:02pm 
I just tested and it is working on my test ship. Turn off via running the program block with the argument "stop" and turn it back on by simply reenabling the programming block.
Make sure your timer block is set to "Run" with a blank argument and not "Run with default argument" and try running the program block with the argument "Reset" to get it working again.
Let me know if it is still having issues.
E-Man720 1 Jul, 2016 @ 4:33pm 
Having issues where a Drive once turned off doesn't work again when turned back on.