Jump to content

Converting position to "orbit position"


Recommended Posts

For a new mod I'm making I'm getting stuck on a technical hurdle.

I want to move a vessel to a location and orbit of the active vessel. The method FlightVessel.orbit.UpdateFromStateVectors() does almost exactly what i want.

Below the code for having the other vessel appear at some distance from the current vessel:

                FlightVessel.GoOnRails();
FlightVessel.orbit.UpdateFromStateVectors(FlightGlobals.ActiveVessel.orbit.pos + offset, FlightGlobals.ActiveVessel.orbit.vel, FlightGlobals.ActiveVessel.orbit.referenceBody, Planetarium.GetUniversalTime());
FlightVessel.GoOffRails();

FlightGlobals.ActiveVessel.orbit.pos gives me the position in relation to what I suspect from the size of the vector to be the celestial body.

FlightGlobals.ActiveVessel.orbit.pos
[-70687.4555733527, 696635.048411489, 31237.3830353896]

What I want to do is to have the other vessel arrive at a specific location in relation to the current vessel. For my mod a few meters in front of a docking port. To do so i have to convert the position of a part to an "orbit" position. How do I do this?

The world reference transform obviously does not work:


FlightGlobals.ActiveVessel.ReferenceTransform.position
(-1472.8, -6.3, -117.8)
transform.TransformPoint(position)
(-1472.8, -6.3, -117.8)

I've tried using transform of the celestial body, but no budge.


FlightGlobals.ActiveVessel.orbit.referenceBody.bodyTransform.InverseTransformPoint(position)
(-395082.6, 31237.0, -578106.6)
FlightGlobals.ActiveVessel.orbit.referenceBody.bodyTransform.TransformPoint(position)
(70264.6, -31249.6, -695713.4)

It should be doable I think. The vector FlightGlobals.ActiveVessel.orbit.pos is literally spot on (if i set the offset to zero, there are some awesome explosions). Just can't seem to convert another vector to wherever this orbit.pos is measured from.

Any suggestion on how to approach this?

Link to comment
Share on other sites

Try

FlightGlobals.ActiveVessel.ReferenceTransform.position - FlightGlobals.ActiveVessel.mainBody.transform.position

or perhaps

(FlightGlobals.ActiveVessel.ReferenceTransform.position - FlightGlobals.ActiveVessel.mainBody.transform.position).xzy

Edited by The_Duck
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...