Jump to content

Adjusting part/vessel mass in flight


Recommended Posts

I'm maintaining the USAF Orion mod, and it's been noticed that vessel mass is not decreasing as pulse units are expended.  I chucked in some diagnostic logging and what seems to be happening is the parts (essentially custom fuel tanks) are decreasing in mass, but the vessel isn't.

So, adjusting the mass of a pulse unit magazine is done with this super complex formula;

                    this.mass = (this.bombStockpile * this.bombMass) + this.dryMass ;
                    Debug.Log("[USAFOrion] adjusted mass of magazine " + this.bombStockpile + " to " + this.mass);

With my little debug line.  And mass (and bombStockpile) decrease as the units are used up.

But when I add in;

Debug.Log("[USAFOrion] Nominally this should have updated the vessel mass.  It now shows : " + vessel.totalMass);

the vessel doesn't change mass at all.  Even if I run 

            vessel.UpdateResourceSets();
            base.onPartFixedUpdate () ;

which would seem to be the sort of thing you do to recalc vessel things.

So,

A: Am I adjusting the part mass at all, or just some value that doesn't actually come into play anywhere?
B: If (A:), is there a way of triggering KSP to recalculate mass (and CoM) of the vessel? 

 

Link to comment
Share on other sites

Don't adjust part mass directly (since 1.0 if memory serves). You need to implement the IPartMassModifier interface (alternatively just use a resource?).

Example implementation: 
https://github.com/Crzyrndm/B9-PWings-Fork/blob/master/B9 PWings Fork/WingProcedural.cs
https://github.com/Crzyrndm/B9-PWings-Fork/blob/master/B9 PWings Fork/WingProcedural.cs#L3312-L3322

Link to comment
Share on other sites

9 minutes ago, Crzyrndm said:

Don't adjust part mass directly (since 1.0 if memory serves). You need to implement the IPartMassModifier interface (alternatively just use a resource?).

Example implementation: 
https://github.com/Crzyrndm/B9-PWings-Fork/blob/master/B9 PWings Fork/WingProcedural.cs
https://github.com/Crzyrndm/B9-PWings-Fork/blob/master/B9 PWings Fork/WingProcedural.cs#L3312-L3322

If I was working from scratch I think I would use a resource without a second thought, and just make sure it's only ever used in discrete amounts.  But there's a lot of code already in place, so I'm trying to just get the existing stuff working.

Having a look now at the IPartMassModifier.

Thanks

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...