Jump to content

[Plugin 0.14.4] Part gravity - v1.0


The_Duck

Recommended Posts

This plugin lets parts have their own gravitational fields:

xaqxY.png

It comes with three gravitating parts: the above-pictured munlet by NovaSilisko, the 500m asteroid by JellyCubes, and a black hole. The munlet has weak gravity and you can land on it. The 500m asteroid has somewhat stronger (but still weak) gravity (the asteroid it seems to have some collider problems or something, so you explode if you try to land on it). The black hole has lethally strong gravity if you get too close.

Thanks to NovaSilisko and JellyCubes for allowing their parts to be packaged with this plugin.

yG3Zr.png

VCpyT.png

In addition to these three parts, it\'s easy to create new gravitating parts or edit part.cfg to give existing parts gravitational fields.

Download here (source included). Unzip in your main KSP folder to install.

Bonus: An empty save file with some of these gravitating objects already scattered around the Kerbin system.

One limitation is that the gravity only works while the part is off-rails, which means it has to be within around 2.5km of the active ship. As a consequence, if e.g. you leave a ship in orbit around a black hole, it will drift away from the black hole if you switch away and do something else. However, within 2.5km there is true n-body gravity, with everything nearby feeling simultaneously the gravity of the dominant body in the SOI and any gravitating parts nearby. Plus, gravity acts on each part of your ship separately, which means that tidal effects are possible. This is particularly noticeable when you swing close to a black hole.

To actually play with these parts you need to rendezvous with them in orbit; I\'ve found RinComp a particularly useful tool for this.

Here\'s how to edit these gravitating parts or create new ones:

To give any part a gravitational field, find the line in part.cfg that starts 'module = ' and change it to 'module = ARGravitatingPart'. Then a few cfg parameters determine the gravitational behavior of the part:

radius - Ideally this is equal to the radius of the part (in meters), if the part is approximately spherical. The gravity of the part is that of a uniform density sphere with this radius.

geesAtRadius - The gravitational acceleration in gees at the above radius (i.e., the surface gravity in gees if the part is a sphere of that radius). Kerbin surface gravity = 1 gee = 9.81 m/s^2. The gravitational acceleration at a distance r from the center of the part is (9.81 m/s^2) * geesAtRadius * (radius / r)^2 - the inverse square law. But inside the radius (if it\'s possible to get inside the radius) the gravitational acceleration is given by (9.81 m/s^2) * geesAtRadius * (r / radius) - increasing linearly with radius.

deployedMass - The part mass will be increased to this value once the part is detached from a commandable ship. This should probably be much larger than the typical mass of a ship. If not, gravity between this part and a ship will mainly pull this part around instead pulling the ship around. This parameter exists so that part can have a small regular mass (under 'standard part parameters') and be launched into orbit on a rocket, but then gain a more realistic large mass once it\'s deployed. If you don\'t set this parameter, the part mass will just stay at the regular mass.

gravitateWhileCommandable - Whether the part\'s gravitational field exists while the part is part of a commandable vessel. Default value is true. One reason to set this to false is to prevent a part with powerful gravity from sucking up spent stages if it is launched on a rocket. If this is false, the part will only start to gravitate once it is detached from a commandable ship.

Link to comment
Share on other sites

Not on rails, but otherwise you should be able to.

What I\'m saying is, does the game support drawing orbits around 'ships' ?

I gave it a try, rendez-vous\'d with the asteroid, but it disappeared as soon as I touched it. I couldn\'t feel much gravity, but it was probably too small to have much of an effect.

Link to comment
Share on other sites

So far I have only set up the little mun on a high kerbin orbit (beyond the real Mun), and experienced a lot of lag when my ship approached within 2.5km of the little mun.

That sounds like the debug log might be getting flooded with messages, causing lag. If it happens again, can you press Alt-F2 to bring up the debug console and report what\'s being printed there, if anything?

Link to comment
Share on other sites

That sounds like the debug log might be getting flooded with messages, causing lag. If it happens again, can you press Alt-F2 to bring up the debug console and report what\'s being printed there, if anything?

Here\'s your debug console. Pretty much the same story, got close to the munlet and it totally lagged out. Was within 800m but it was uncontrollable due to lag. KSP crashed shortly after the screenshot. Hope it helps!

screenshot59.png

Link to comment
Share on other sites

Here\'s your debug console. Pretty much the same story, got close to the munlet and it totally lagged out. Was within 800m but it was uncontrollable due to lag. KSP crashed shortly after the screenshot. Hope it helps!

Ah, an old familiar 'can\'t add component' ::)

The_Duck, I\'m not sure this is your case -- but here\'s how I got rid of that message in the cart plugin:

protected override void onPack() {
// Here destroy EVERY rigidbody and joint you\'ve added to the part. Colliders
// may stay (if they\'re not attached to the manually created rigidbody).
base.onPack();
}
protected override void onPartFixedUpdate() {
if( ( rigidbody != null ) &&
( !rigidbody.isKinematic ) ) {
// Here create rigidbodies and joints again.
}
base.onPartFixedUpdate();
}

Link to comment
Share on other sites

Well, I managed to get the console errors here too, and I\'m not sure, but I think they may be because the .sfs file is messed up, as opposed to being caused by the plugin code itself. The game seems to be repeatedly trying to load the vessel that you are approaching, and repeatedly failing. I\'ll remove the 'bonus' save file download from the first post and see if I can\'t put together one that doesn\'t cause these errors.

Link to comment
Share on other sites

All right, after a fair amount of experimentation it seemed like there was some problem with the Munlet vessels in the save file I was providing. I\'ve re-done the save file and I seem to have gotten rid of the errors. Try out the new save file and let me know if that\'s not the case! You can find the download in the first post.

Link to comment
Share on other sites

I just downloaded it again but it\'s a V10, is it supposed to be named the same version? I\'ll give it a try tonight!

Edit: I have not downloaded any save files, only the part/plugins themselves, are these updated? If they are I\'ll test them and post results :)

Link to comment
Share on other sites

I just downloaded it again but it\'s a V10, is it supposed to be named the same version? I\'ll give it a try tonight!

Edit: I have not downloaded any save files, only the part/plugins themselves, are these updated? If they are I\'ll test them and post results :)

The code hasn\'t changed, only the save file I provided. But did you use some sort of manual or automatic save editor to set up the munlet you experienced lag with earlier? I am not 100% sure of this, but my current best hypothesis is that this lag is caused by a bad save file and not the plugin code. As an alternative to save file editing, it\'s possible to launch the munlet or black hole on ships. You might try this and if a launched munlet worked without lag, that would be evidence that the problem is from the edited save file and not the plugin code.

Link to comment
Share on other sites

I was able to land on the Munlet, or more exactly 'gently stick' to it. On my next mission, I\'m going to try to deorbit it.

However, I hardly feel any pull when I approach the Asteroid and when I touched it (very gently) my ship exploded.

screenshot26d.png

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...