Jump to content

Part Gravity Code


Recommended Posts

Apologies in advance for any ranting, simply thinking of Squad-code induces compulsive rage.

Q:

-Does anyone know how gravity is handled in code now?

-From what I remember, it was handled (back in 2012) in some hidden method of the ancient Part class, and all the gravity modifying mods had to recompute the gravity of every single part, and apply a second force with opposite vector, doubling the instructions just to get back to base, this was beyond stupid. I also remember that when PartModule came out, Squad just dragged along nearly all the ancient code, and stuck it in a new package. From what I understand, Squad in their infallible omniscience decided at some following point to obfuscate their magnificent contribution to programming, which if they did what I think they did, means they're now feeding their entire code base through maximal method overload and rename routines, which I suspect means getting ahold of the damn misanthropic gravity method is now well and truly impossible.

-Can anyone confirm this is the case, or tell me how to acquire the object?

Reason for Q:

The idea I had was to inject a tiny amount of ontological sanity and modability into the stew, and create an actual "public sealed Gravity" object, and possibly other basic physics-system objects, collision being the only truly non-trivial system(and best left to Unity for now).

The Gravity object doesn't actually handle gravity, it's just a publicly accessible immutable container for links to the code that does. Inside Gravity are interface properties, which initialize to the default Squad code implementation; and a few general control properties which specify or report things like whether "vessel-based" or "part-based" implementation is being used, "2-body" or "n-body" computations are in effect, what's overridden, who's responsible, versioning, and whatever else needs tracking. This allows some sanity to be used with all the obsessive compulsive code hiding and obfuscation: Leave the damn Gravity object and interfaces alone, mark the actual SQUAD IMPLEMENTATION private/internal/whatever, obfuscate the implementation only, and simply set those hidden objects as the default initialization values of the interface properties.

Doing something like this will allow the modding community to actually mod the game in depth, in ways the dev team didn't think of, without compromising Squad's actual IP, or having any need to document/reference any of the source code that doesn't have a valid reason for being public. The best part is that this is how C# is actually intended to work in the first place.

One other benefit of separating and properly organizing physics code out of unity is that the Kraken can be truly slain, at least in theory, and high-mass restrictions can be resolved. Aside from collision handling, the actual implementation of the physics required by KSP is very nearly trivial, well documented all over the net, and not really THAT much work, even using native code. Using custom implementations means KSP can finally have a physics system that does what KSP actually needs it to do, instead of what Unity thought was a good idea to borrow from PhysX.

The difficult part of this is putting together a comprehensive framework in C# to tie it all together, and properly handle modding, and properly hide the implementation that actually deserves it from decompilation/theft. Unfortunately, it's precisely the high level architecture and planning that I've seen Squad fail at the most miserably.

Link to comment
Share on other sites

You can still simply apply a force to an rigidbody in the old Unity fashion, check out the Script Reference for more on that. Link to Rigidbody.AddForce. Vessels themselves aren't rigidbodies, so you'll have to apply a force to each individual part. There is an N-body mod out there somewhere as well, but it does not perform part-part gravitic interactions (since they're so minute that they basically don't matter).

If you want to implement a better PhysX system, you can either wait until Unity 5 (which involves an upgrade to PhysX 3.3, IIRC) or try to implement it yourself via sticking a .dll into the GameData folder. The issue with the Kraken and co. is unfortunately an innate part of the physics systems, and Squad has already handled many of the Krakens that have shown up in the game. What you see now in terms of Kraken attacks are pathetic compared to the original Kraken, from what I've heard.

Link to comment
Share on other sites

The actual force are applied by the FlightIntegrator instance of the vessel. So if you wanted to change what's going on you could just change the FlightIntegrator of the vessel and you'd get a new gravity/drag/anyOtherForce.

But that would not change the orbit for the non loaded ship since they use Orbit, which implements the equations for 1 object orbiting an other.

You can't just define a "Gravity" object because non loaded object are on rail and don't have a force applied to them but just use a equation defined in Orbit.

An while I agree that the game could be a bit more modular and allow for deeper mod change without trick I also think you could ask for change without turning your post into rant/Squad attack.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...