Jump to content

PART.MASS VS RIGIDBODY.MASS


Recommended Posts

Trying to make a plugin to modify the part mass. Find out that there are 2 mass we can play with.

part.mass VS rigidbody.mass.

Which one is consider as the "main" diameter when KSP doing physical calculation?

Is it possible we make a part negative mass and plus the resource mass, it will come to positive mass?

What is the best way when I want to return its mass?

What would happen if I set a part zero mass and doesn't turn off PhysicsSignificance?

I try to reduce a part mass when it is floating on the sea, it fly to the sky as soon as I press the button, what is the best way to do this?

Link to comment
Share on other sites

1 hour ago, flywlyx said:

Which one is consider as the "main" diameter when KSP doing physical calculation?

The rigidbody mass is what the Unity PhysX calculations use to simulate the physics.  I'm not sure you would be able to change this without KSP changing it back on the next physics update (KSP has to update the rigidbody mass each physics update to account for part masses changing when the amounts of resources it holds change).

1 hour ago, flywlyx said:

Is it possible we make a part negative mass and plus the resource mass, it will come to positive mass?

It is "possible" though it will probably cause all manner of strange bugs as it really isn't logical and writing code to handle negative masses "correctly" (whatever that means, have you ever seen anything with negative mass?) would be a waste of effort.  Also, at some point as the resource drains, the mass will be very close to (or actually at) zero which will cause other issues (see below).

2 hours ago, flywlyx said:

What is the best way when I want to return its mass?

I assume you mean what is the best way to read the mass from a Part.  This has changed and been extended several times but basically, part.mass should be the dry mass.  I'm not at home at the moment so can't look it up but I know you can add up the mass of the resources yourself or you should be able to call Part.GetResourceMass().  There is also a mechanism for PartModules to modify the mass of a part but I'll definitely need to look up the details of that later to be sure if it is included in Part.mass directly or you need to adjust.  I'll try to update this post sometime this evening (GMT).

2 hours ago, flywlyx said:

What would happen if I set a part zero mass and doesn't turn off PhysicsSignificance?

a = F / m

Something would probably break inside the PhysX calculations (at least).  Almost anything could happen, from nothing untoward to "infinite" acceleration being applied to that part resulting in spontaneous disassembly of the vessel and/or it disappearing off to Alpha Centauri at, or well above, the speed of light...

2 hours ago, flywlyx said:

I try to reduce a part mass when it is floating on the sea, it fly to the sky as soon as I press the button, what is the best way to do this?

A part floating one the sea is in equilibrium with the weight force balanced by the buoyancy force.  If you suddenly change the mass to a significantly lower value then the forces will no longer be in equilibrium and the part will accelerate upwards.  I'm a bit surprised it actually takes off but I guess that depends on how much you are changing it by.

You should probably reconsider what you are trying to do as directly messing with part masses (especially during flight) is probably not the best way to achieve what you are actually trying to do. I would suggest asking for advice about what you are actually trying to achieve rather than about how you think you might be able to do it.  In general, doing something to a part during flight that breaks the laws of physics is likely to cause several obvious issues and quite likely to cause several much less obvious (but potentially just as dangerous) ones.

Link to comment
Share on other sites

1 hour ago, Padishar said:

The rigidbody mass is what the Unity PhysX calculations use to simulate the physics.  I'm not sure you would be able to change this without KSP changing it back on the next physics update (KSP has to update the rigidbody mass each physics update to account for part masses changing when the amounts of resources it holds change).

I change the part.mass and rigidbody.mass at the same time, but cant eliminate the resources mass, so I think it is updated every fix update.

1 hour ago, Padishar said:

It is "possible" though it will probably cause all manner of strange bugs as it really isn't logical and writing code to handle negative masses "correctly" (whatever that means, have you ever seen anything with negative mass?) would be a waste of effort.  Also, at some point as the resource drains, the mass will be very close to (or actually at) zero which will cause other issues (see below).

I will update it every frame, so it will be safe in some way.

2 hours ago, Padishar said:

I assume you mean what is the best way to read the mass from a Part.  This has changed and been extended several times but basically, part.mass should be the dry mass.  I'm not at home at the moment so can't look it up but I know you can add up the mass of the resources yourself or you should be able to call Part.GetResourceMass().  There is also a mechanism for PartModules to modify the mass of a part but I'll definitely need to look up the details of that later to be sure if it is included in Part.mass directly or you need to adjust.  I'll try to update this post sometime this evening (GMT).

Not really, since I have change all the part.mass and rigidbody.mass, I am looking for a way to get the original mass of the part.

2 hours ago, Padishar said:

Something would probably break inside the PhysX calculations (at least).  Almost anything could happen, from nothing untoward to "infinite" acceleration being applied to that part resulting in spontaneous disassembly of the vessel and/or it disappearing off to Alpha Centauri at, or well above, the speed of light...

I try to avoid this situation, so I put them on rail and fly faster than light.

2 hours ago, Padishar said:

A part floating one the sea is in equilibrium with the weight force balanced by the buoyancy force.  If you suddenly change the mass to a significantly lower value then the forces will no longer be in equilibrium and the part will accelerate upwards.  I'm a bit surprised it actually takes off but I guess that depends on how much you are changing it by.

I trying to make a fix for the problem the heavy boats take off during the load, obviously, this is a failure.

2 hours ago, Padishar said:

You should probably reconsider what you are trying to do as directly messing with part masses (especially during flight) is probably not the best way to achieve what you are actually trying to do. I would suggest asking for advice about what you are actually trying to achieve rather than about how you think you might be able to do it.  In general, doing something to a part during flight that breaks the laws of physics is likely to cause several obvious issues and quite likely to cause several much less obvious (but potentially just as dangerous) ones.

What I am trying to make is a equipment called "mass effect drive", so I have to mass up parts' masses.

Until now, most of the function works as I expected, unity physics looks pretty tolerate to small amount changes on mass, but there are 2 problems really hard to solve.

1, resource mass cant be removed, this is why I come up with a negative mass idea and wonder if it can be fix this way.

2,  get the part original mass the return it back to part," protoPartSnapshot" would be my solution, but I don't really know how to use it.

Link to comment
Share on other sites

As it stands, KSP will take part.mass, add the mass of any resources, and use that to set the rigidbody mass every physics frame.  In 1.1 it will take the part prefab mass, add resource mass and module masses, and use that to set part.mass and the rigidbody mass.  For now, the best way to change a part's mass is to change part.mass.  In 1.1, you will have to have a module that implements IPartMassModifier and calculate the change in mass that you want.

Link to comment
Share on other sites

1 hour ago, flywlyx said:

What I am trying to make is a equipment called "mass effect drive", so I have to mass up parts' masses.

Why do you have to?  This was my point, you don't have to program it the same way that it "works" in "reality", you just need to get the same apparent effect.  If you can calculate how much acceleration your drive generates then you can simply accelerate the vessel by that much, either by applying a force to the drive part that will generate the required acceleration or, if the forces are huge and break the vessel, by putting the vessel on rails and simply changing the orbital parameters.

27 minutes ago, blowfish said:

In 1.1 it will take the part prefab mass, add resource mass and module masses, and use that to set part.mass and the rigidbody mass.

Citation needed.  Any official word on this or is it just guesswork?

Link to comment
Share on other sites

12 minutes ago, Padishar said:

Why do you have to?  This was my point, you don't have to program it the same way that it "works" in "reality", you just need to get the same apparent effect.  If you can calculate how much acceleration your drive generates then you can simply accelerate the vessel by that much, either by applying a force to the drive part that will generate the required acceleration or, if the forces are huge and break the vessel, by putting the vessel on rails and simply changing the orbital parameters.

Since we cant get the force applied on the vessel, we are always one frame late(at least). This might not be a big issue. But the worse one is, all the mass indicators are going to indicate the "true" mass of your ship. And none of the MJ staff will work. This sounds really weirdd to me.

40 minutes ago, blowfish said:

As it stands, KSP will take part.mass, add the mass of any resources, and use that to set the rigidbody mass every physics frame.  In 1.1 it will take the part prefab mass, add resource mass and module masses, and use that to set part.mass and the rigidbody mass.  For now, the best way to change a part's mass is to change part.mass.  In 1.1, you will have to have a module that implements IPartMassModifier and calculate the change in mass that you want.

Sounds like official "solution" to Mass effect drive:cool:

18 minutes ago, Padishar said:

Citation needed.  Any official word on this or is it just guesswork?

http://forum.kerbalspaceprogram.com/index.php?/topic/133285-devnote-tuesday-super-tuesday/

Something related here.

Edited by flywlyx
Link to comment
Share on other sites

5 minutes ago, NathanKell said:

Slight correction: part.mass will be (prefab mass) + (for each IPartMassModifier, GetModuleMass() ). Resource mass is still separate, but is cached in part.resourceMass.

So, I still have to consider the negative mass if I want to have a "mass-modifier"? Or I could play with the part.resourceMass at the same time?

Link to comment
Share on other sites

6 hours ago, NathanKell said:

To mangle Nietzsche, if you break physics, physics also breaks you. I really, really don't recommend doing any physics-breaking. As was said upthread, it's liable to end in tears.

That which does not break us makes us stronger:cool: It Never Hurts to Try.

Link to comment
Share on other sites

12 hours ago, sarbian said:

Clearly you don't have to handles "bugs" in MJ or KER with mods that thinks physic is boring.

How boring the physic is really depends on how less you know about it.

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