Jump to content

Get any arbitrary velocity vector expressed in surface-relative frame of reference?


Recommended Posts

You can get the surface velocity of a vessel using Vessel.srf_velocity.

But looking all through here:

https://github.com/Anatid/XML-Documentation-for-the-KSP-API

I can't find the way to get the same information about a celestial body orbiting its primary celestial body. If a vessel was in orbit around Kerbin in a circular orbit at 11,400,000 altitude, it could report both its orbital velocity and its surface velocity relative to Kerbin. But when the Mun is in orbit around Kerbin at that distance, it can't. It only gives its orbital velocity. Is there a way to get its surface velocity too?

I tried calling CelestialBody.GetSrfVelocity() but as far as I can tell it always returns (0,0,0) - making me think it's the velocity relative to the body itself rather than the velocity relative to its parent it's orbiting.

It would make sense if CelestialBody had a frame of reference transformation function that took any orbital velocity and returned the surface velocity version of it, but I can't seem to find it.

Link to comment
Share on other sites

Wow bad timing. Answered my own question almost right after I asked it.

The answer is this:

assuming b = a CelestialBody

and parent = that CelestialBody's parent body.


surfaceVelocity = b.orbit.GetVel() - parent.getRFrmVel( b.position );

getRFrmVel() is the conversion I was looking for. You pass in a position in Unity world 3D coords, and it returns the velocity vector representing the offset difference between orbital and surface velocities at that location. You have to tell it the position, of course, because the closer to the equator plane the object is, the bigger the difference between the two is. An object above the north pole would show zero difference between the two.

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