Jump to content

forces on kerbin


Recommended Posts

Hi all.

i try to run this code on an eva kerbal

v.transform.rigidbody.AddForceAtPosition(-FlightGlobals.getGeeForceAtPosition(v.transform.position) * v.GetTotalMass(), v.findWorldCenterOfMass());

v is flightglobal vessel

the trouble is that the kerbal slowly flying upwards. what other forces are affecting a still vessel on a planetsurface?

thanks

Link to comment
Share on other sites

Err, can you hyperedit to the otherside of the planet?

My first guess is that you are nullifying the force of gravity on the kerbal, but the planet is still moving in World Space while the Kerbal is staying stationary in World Space.

If so, by hyperediting to the otherside of the planet, the kerbal will stay on the ground as the planet is moving towards him.

D.

Link to comment
Share on other sites

My first guess is that you are nullifying the force of gravity on the kerbal, but the planet is still moving in World Space while the Kerbal is staying stationary in World Space.

There's that, or any slight impulse from contact with a surface

Link to comment
Share on other sites

Hi all.

i try to run this code on an eva kerbal

v.transform.rigidbody.AddForceAtPosition(-FlightGlobals.getGeeForceAtPosition(v.transform.position) * v.GetTotalMass(), v.findWorldCenterOfMass());

v is flightglobal vessel

the trouble is that the kerbal slowly flying upwards. what other forces are affecting a still vessel on a planetsurface?

thanks

transform.position is world space. Are you sure that the getGeeForceAtPosition method uses world or local space? Does this code work for just a vessel? or does it only break on EVA'd kerbals?

Link to comment
Share on other sites

it gives world coords and it does the same for other vessels too, though one fault was that i was testing it with running it in onupdate and forgot about it, that made the force so strong. now its running in onfixedupdate its a lot better still its flying straight up, doesnt matter which side of kerbin it is :(

edit: its rigidbody has velocity so the first theory surely not true. its not the planet moves away from the still vessel

Edited by Tuareg
Link to comment
Share on other sites

At this point, I would do a Vector3.Distance(WorldPosThisFrame,WorldPosLastFrame); in FixedUpdate and compare the distances between them. If the distances are the same (constant velocity) you are correctly canceling everything and the kerbal has no forces acting upon it.

If the distances are different, either you are not canceling the force of gravity correctly, or there is another force acting on the kerbal.

Also, you are running this in FixedUpdate, not Update correct? Update is for GUI stuff and on most computers runs more often then FixedUpdate where KSP exerts forces so you could be canceling gravity too often.

D.

Link to comment
Share on other sites

If you want to stop gravity from effecting the kerbal, wouldn't the Unity "useGravity" flag be a better solution?

http://docs.unity3d.com/ScriptReference/Rigidbody-useGravity.html

Also, to get the current gravity that is applied to the objects, "Physics.gravity" might be a more accurate reference. And I would use the "AddForce" instead of "AddForceAtPosition" function. With the ForceMode to acceleration, so you do not need to multiply with the mass, which could also be your problem, as the mass presented to GetTotalMass might not be the same as the physics mass.

http://docs.unity3d.com/ScriptReference/ForceMode.html


v.transform.rigidbody.AddForce(Physics.gravity, ForceMode.Acceleration);

Link to comment
Share on other sites

has it something to do with the rotation of the planet?

no, in that case the vessel should move sideaways but it flies straight up.

At this point, I would do a Vector3.Distance(WorldPosThisFrame,WorldPosLastFrame); in FixedUpdate and compare the distances between them. If the distances are the same (constant velocity) you are correctly canceling everything and the kerbal has no forces acting upon it.

If the distances are different, either you are not canceling the force of gravity correctly, or there is another force acting on the kerbal.

Also, you are running this in FixedUpdate, not Update correct? Update is for GUI stuff and on most computers runs more often then FixedUpdate where KSP exerts forces so you could be canceling gravity too often.

D.

yes, im now running it in fixedupdate and the velocity is increasing so it has acceleration

If you want to stop gravity from effecting the kerbal, wouldn't the Unity "useGravity" flag be a better solution?

http://docs.unity3d.com/ScriptReference/Rigidbody-useGravity.html

Also, to get the current gravity that is applied to the objects, "Physics.gravity" might be a more accurate reference. And I would use the "AddForce" instead of "AddForceAtPosition" function. With the ForceMode to acceleration, so you do not need to multiply with the mass, which could also be your problem, as the mass presented to GetTotalMass might not be the same as the physics mass.

http://docs.unity3d.com/ScriptReference/ForceMode.html


v.transform.rigidbody.AddForce(Physics.gravity, ForceMode.Acceleration);

as far as i know ksp doesnt use gravity, they use forces applied at CoM and this is also why i cant use addforce instead of addforceatposition. the CoM of the vessel is not the same as the center of the rigidbody. i can be wrong though

Link to comment
Share on other sites

as far as i know ksp doesnt use gravity, they use forces applied at CoM and this is also why i cant use addforce instead of addforceatposition. the CoM of the vessel is not the same as the center of the rigidbody. i can be wrong though

AddForce on a kerbal seems to work fine for me. Setting vessel.transform.ridigbody.useGravity to false does not seem to do much.

But I do see a small upwards drift that you're also seeing. So the actual downwards force that the object gets is less then the added upwards force.

Few random ideas:

* FlightGlobals.getCentrifugalAcc and/or FlightGlobals.getCoriolisAcc might also get applied?

* Drag could be causing strange effects? (We know the drag model isn't that awesome)

As cheat, you could set the velocity to zero when it's nearly zero?

Link to comment
Share on other sites

AddForce on a kerbal seems to work fine for me. Setting vessel.transform.ridigbody.useGravity to false does not seem to do much.

But I do see a small upwards drift that you're also seeing. So the actual downwards force that the object gets is less then the added upwards force.

Few random ideas:

* FlightGlobals.getCentrifugalAcc and/or FlightGlobals.getCoriolisAcc might also get applied?

* Drag could be causing strange effects? (We know the drag model isn't that awesome)

As cheat, you could set the velocity to zero when it's nearly zero?

genius! thanks a lot :) i didnt think squad took the time to actually model centrifugal force but they did. my little kerbal can now levitate on kerbin \o/

Link to comment
Share on other sites

genius! thanks a lot :) i didnt think squad took the time to actually model centrifugal force but they did. my little kerbal can now levitate on kerbin \o/

You're welcome. I like investigating interesting cases like this :-) for the record, which combination worked?

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