Jump to content

Restoring a vessel's orbit


blizzy78

Recommended Posts

TL;DR: Looking for code to "teleport" a vessel to a previously-stored position, all the while restoring a previously-stored orbit of said vessel.

Hi, in one of my mods I'm wanting to add a "back" button to tutorial pages. This would make the tutorial display the previous page as well as restore the current vessel's orbit as it has been before leaving said page.

Now, the problem I have is in restoring said orbit. I've already gone so far as to looking at HyperEdit's source to see how an orbit can be manipulated, which is quite straightforward. So the problem is not so much restoring the orbit itself, that part works fine. It's the vessel's position in the orbit that I can't seem to find a way to restore. For example, if I have a vessel in a circular orbit with the vessel being right above KSC, then timewarp half an orbit, then restore the orbit back to where it was, the vessel should be right above KSC again.

I've also already tried setting the vessel's orbit's "vel" and "pos" fields with values I've stored before, along with setting those in the vessel's OrbitDriver, to no avail. (sorry I can't quite remember the code, I'm at work right now)

What's more, I've also tried to not use "orbit.UpdateFromUT(Planetarium.GetUniversalTime())", but "orbit.UpdateFromUT(oldOrbit.startTime)", also the same with the old orbit's epoch. (Again, sorry I can't remember the exact code right now.) Both changes did not help - they didn't even seem to affect anything.

The best I got so far was that for a brief moment (like a flicker), the vessel was in the right position, then immediately jumped forward in its orbit as if its position did never change. (Although the orbit has been restored perfectly like I described.) Of course I can't be sure how the OrbitDriver works, but I'm suspecting it overwrites the vessel's position somehow in the next frame or something like that.

Is there anything I could do to make it restore the vessel's position exactly like it was?

Link to comment
Share on other sites

I think the problem you have is that the orbits are relative to the "univeral time", and as the universal time has changed your orbit position has changed. So you'll have to adjust the orbit position to take away this extra time.

It might be as simple as to generate a new Orbit with the epoch parameter (I think it was called epoch, the one before the reference body), and add the time difference between your stored moment and now.

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