Jump to content

Strange issue with Vessel.GetWorldPos3D()


Recommended Posts

I'm hitting a strange issue with this method.

First, a bit of background:

I'm updating the old NeatherdyneMassDriver mod.  Now, one of the things it does when being armed (using a manual event) is to look at the entire FlightGlobals.Vessels list using this:

            for (int i = 0; i < FlightGlobals.Vessels.Count; i++)

The code only looks at vessels which are loaded.

The strange thing is that upon first runthrough of this after launching a vessel, the GetWorldPos3D returns wrong information, it's actually off by about 18m or so.  I have to either do a Revert to Launch, or change scenes (not Mapview) and return, and then, when I try it again, the values are correct.

Edit:  a few other pieces of info:

  • The vessel is landed
  • It's been staged
  • It's still attached to the ground via Launch Clamps
  • Cycling through all the vessels in range doesn't change this
  • In at least one case (a Kerbal on EVA), the initial reported position is only about 3.7m from the vessel which is on the launch pad, but this kerbal is standing on top of the SPH

 

So, either I shouldn't be calling it when I do, which begs the question of what I should be using to get the current position, or there is something mildly wrong.

Anybody have any ideas about this?

 

Edit 2:  More info:

I added this event to the module:

        [KSPEvent(guiName = "Dump 3dWorldPos", guiActive = true)]
        void DumpAllWorldPos()
        {
            for (int i = 0; i < FlightGlobals.Vessels.Count; i++)
            {
                Log.Info(" vessel: " + FlightGlobals.Vessels[i].GetDisplayName() + ", GetWorldPos3D: " + FlightGlobals.Vessels[i].GetWorldPos3D());
            }
        }

Then I ran it

This first data is right after scene entry (via Launch in VAB):

NeatherdyneMassDriver:  vessel: Ast. HSJ-227, GetWorldPos3D: [-1124879303.97714, -733815128.549169, -575230659.152941]
NeatherdyneMassDriver:  vessel: Bug-E Buggy, GetWorldPos3D: [985.913289922824, 591.861797130415, 1415.44591948658]
NeatherdyneMassDriver:  vessel: Ast. RGM-917, GetWorldPos3D: [-293479531.735809, 431907041.770186, 454418748.74671]
NeatherdyneMassDriver:  vessel: Ast. TMB-379, GetWorldPos3D: [-1023536652.28846, 218600335.368253, 403709979.216618]
NeatherdyneMassDriver:  vessel: Ast. HCD-748, GetWorldPos3D: [-152570086.523338, -127737266.158059, -60279170.0043015]
NeatherdyneMassDriver:  vessel: Ast. OER-301, GetWorldPos3D: [186115770.605457, 51428147.3947904, -5342574886.78443]
NeatherdyneMassDriver:  vessel: Ast. SFB-334, GetWorldPos3D: [-896989968.552023, 153602818.648187, -931489546.981206]
NeatherdyneMassDriver:  vessel: Ast. KNE-432, GetWorldPos3D: [-156166998.831367, -147138502.919713, -1135450874.30196]
NeatherdyneMassDriver:  vessel: Bug-E Buggy, GetWorldPos3D: [972.820820344182, 591.748435160849, 1396.5951393447]
NeatherdyneMassDriver:  vessel: #autoLOC_501174, GetWorldPos3D: [990.145519455868, 508.822024835369, 1430.04441930554]
NeatherdyneMassDriver:  vessel: Bob Kerman, GetWorldPos3D: [436.497802734375, 208.381652832031, 684.302307128906]
NeatherdyneMassDriver:  vessel: m1 Ship, GetWorldPos3D: [493338.263559453, 601047.624391597, -341130.058751659]
NeatherdyneMassDriver:  vessel: M3, GetWorldPos3D: [-11.8811203269019, -0.298791598763315, 8.25047809103551]

Then I reverted to launch, and did it again:

NeatherdyneMassDriver:  vessel: Ast. HSJ-227, GetWorldPos3D: [-1140276075.97325, -733812912.308787, -544015357.766437]
NeatherdyneMassDriver:  vessel: Bug-E Buggy, GetWorldPos3D: [1031.74545127409, 592.166583143299, 1382.56478619274]
NeatherdyneMassDriver:  vessel: Ast. RGM-917, GetWorldPos3D: [-280847806.280659, 431904672.499405, 462329954.84738]
NeatherdyneMassDriver:  vessel: Ast. TMB-379, GetWorldPos3D: [-1012009919.0946, 218597987.064976, 431751248.705451]
NeatherdyneMassDriver:  vessel: Ast. HCD-748, GetWorldPos3D: [-154168133.004789, -127736440.106006, -56050102.0961084]
NeatherdyneMassDriver:  vessel: Ast. OER-301, GetWorldPos3D: [38935875.9285049, 51428088.1133079, -5345635726.95092]
NeatherdyneMassDriver:  vessel: Ast. SFB-334, GetWorldPos3D: [-922286462.306923, 153601919.06607, -906414492.983304]
NeatherdyneMassDriver:  vessel: Ast. KNE-432, GetWorldPos3D: [-187369986.391262, -147141138.537524, -1130708600.31984]
NeatherdyneMassDriver:  vessel: Bug-E Buggy, GetWorldPos3D: [1018.23721994056, 592.053217722987, 1364.00967907606]
NeatherdyneMassDriver:  vessel: #autoLOC_501174, GetWorldPos3D: [1036.30101758615, 509.126778534616, 1397.06556526787]
NeatherdyneMassDriver:  vessel: Bob Kerman, GetWorldPos3D: [466.214141845703, 208.686447143555, 663.813903808594]
NeatherdyneMassDriver:  vessel: m1 Ship, GetWorldPos3D: [485648.511977542, 601047.929163854, -352022.088823108]
NeatherdyneMassDriver:  vessel: M3, GetWorldPos3D: [2.91912340327718, 0.0061136586090001, -2.10437255929283

 

Nothing else was happening.  You can see the differences.

Edited by linuxgurugamer
Link to comment
Share on other sites

More strange data.  I also dumped the rootPart.transform.position and localPosition:

After initial launch:

NeatherdyneMassDriver:  vessel: Bug-E Buggy, GetWorldPos3D: [1086.77102203531, 592.044072977757, 1309.96491621492]
NeatherdyneMassDriver: rootPart.transform.position: (1086.3, 592.9, 1309.7), localPosition: (1086.3, 592.9, 1309.7)

NeatherdyneMassDriver:  vessel: Bob Kerman, GetWorldPos3D: [499.578002929688, 208.686447143555, 638.983093261719]
NeatherdyneMassDriver: rootPart.transform.position: (499.7, 208.7, 638.8), localPosition: (499.7, 208.7, 638.8)

NeatherdyneMassDriver:  vessel: m1 Ship, GetWorldPos3D: [466983.310392697, 601047.929188322, -376431.481721794]
NeatherdyneMassDriver: FlightGlobals.Vessels[i].rootPart is null

NeatherdyneMassDriver:  vessel: M3, GetWorldPos3D: [0.44120117035064, 0.000965883546492917, -0.362673875655871]
NeatherdyneMassDriver: rootPart.transform.position: (0.0, 0.0, 0.0), localPosition: (0.0, 0.0, 0.0)

NeatherdyneMassDriver:  vessel: M3 Ship, GetWorldPos3D: [11.8329111559249, 0.0257798374724112, -9.52662166945031]
NeatherdyneMassDriver: rootPart.transform.position: (9.1, 0.0, -7.4), localPosition: (9.1, 0.0, -7.4)

Stage to drop a rover, did dump:

NeatherdyneMassDriver:  vessel: Bug-E Buggy, GetWorldPos3D: [1120.83791006944, 591.739257621672, 1280.74852505534]
NeatherdyneMassDriver: rootPart.transform.position: (1120.4, 592.6, 1280.5), localPosition: (1120.4, 592.6, 1280.5)

NeatherdyneMassDriver:  vessel: Bob Kerman, GetWorldPos3D: [509.252349853516, 208.381591796875, 631.922424316406]
NeatherdyneMassDriver: rootPart.transform.position: (509.4, 208.4, 631.8), localPosition: (509.4, 208.4, 631.8)

NeatherdyneMassDriver:  vessel: m1 Ship, GetWorldPos3D: [452741.237589635, 601047.624378752, -393418.124642584]
NeatherdyneMassDriver: FlightGlobals.Vessels[i].rootPart is null

NeatherdyneMassDriver:  vessel: M3, GetWorldPos3D: [-13.1975449720675, -0.30380933305704, 11.4401824400219]
NeatherdyneMassDriver: rootPart.transform.position: (-13.6, -0.3, 11.8), localPosition: (-13.6, -0.3, 11.8)

NeatherdyneMassDriver:  vessel: M3 Ship, GetWorldPos3D: [-2.13696753375828, -0.278870520863944, 1.84792338724525]
NeatherdyneMassDriver: rootPart.transform.position: (-4.8, -0.3, 4.1), localPosition: (-4.8, -0.3, 4.1)

Now, Revert to Launch, data dump:


NeatherdyneMassDriver:  vessel: Bug-E Buggy, GetWorldPos3D: [1198.35686397526, 592.044047439737, 1208.78288220479] 
NeatherdyneMassDriver: rootPart.transform.position: (1197.9, 592.9, 1208.5), localPosition: (1197.9, 592.9, 1208.5)

NeatherdyneMassDriver:  vessel: Bob Kerman, GetWorldPos3D: [554.14453125, 208.686431884766, 592.339294433594]
NeatherdyneMassDriver: rootPart.transform.position: (554.3, 208.7, 592.2), localPosition: (554.3, 208.7, 592.2)

NeatherdyneMassDriver:  vessel: m1 Ship, GetWorldPos3D: [431876.346159911, 601047.929157477, -416241.400248739]
NeatherdyneMassDriver: FlightGlobals.Vessels[i].rootPart is null
 
NeatherdyneMassDriver:  vessel: M3, GetWorldPos3D: [5.14173325152179, 0.0120963886386356, -4.9437057897468]
NeatherdyneMassDriver: rootPart.transform.position: (0.0, 0.0, 0.0), localPosition: (0.0, 0.0, 0.0)

and after the stage:

NeatherdyneMassDriver:  vessel: Bug-E Buggy, GetWorldPos3D: [1198.35686397526, 592.044047439737, 1208.78288220479]
NeatherdyneMassDriver: rootPart.transform.position: (1197.9, 592.9, 1208.5), localPosition: (1197.9, 592.9, 1208.5)

NeatherdyneMassDriver:  vessel: Bob Kerman, GetWorldPos3D: [554.14453125, 208.686431884766, 592.339294433594]
NeatherdyneMassDriver: rootPart.transform.position: (554.3, 208.7, 592.2), localPosition: (554.3, 208.7, 592.2)

NeatherdyneMassDriver:  vessel: m1 Ship, GetWorldPos3D: [431876.346159911, 601047.929157477, -416241.400248739]
NeatherdyneMassDriver: FlightGlobals.Vessels[i].rootPart is null

NeatherdyneMassDriver:  vessel: M3, GetWorldPos3D: [0.409642573143623, 0.000956518032801253, -0.391522816661819]
NeatherdyneMassDriver: rootPart.transform.position: (0.0, 0.0, 0.0), localPosition: (0.0, 0.0, 0.0)

NeatherdyneMassDriver:  vessel: M3 Ship, GetWorldPos3D: [10.9532604016493, 0.0258284093342764, -10.5336008646836]
NeatherdyneMassDriver: rootPart.transform.position: (8.5, 0.0, -8.1), localPosition: (8.5, 0.0, -8.1)

 

So, things are wonky after the launch, the values change from before the staging to after.

After the Revert to Launch, the values (which are different from the first set) stay the same between the pre-stage and post-stage

 

Link to comment
Share on other sites

I would guess that load and revert do set up the universe differently, and since any choice of origin is arbitrary, does it matter ?

Compare rootPart.rb.worldCenterOfMass and vessel.mainBody.position with vessel getWorldPos3D: If all change, simply the origin was choosen different.

Link to comment
Share on other sites

GetWorldPos3D() return the position of the vessel CoM (it just return the Vessel.CoMD field), not the position of the vessel GO transform.
As for the differences in various states, that is quite normal due to the floating origin system, the rotating/non rotating frame, the physics easing, etc
There is zero guarantee that the absolute position of things will be the same for a given point in time.
Not sure what you are trying to do in the first place, but as a general rule you can only compare relative positions.

Link to comment
Share on other sites

  • 5 weeks later...

EDITED:  I had to revisit my old work and I made a few mistakes on my original post.  Changes are underlined, corrections are in bold.

When you first load a vessel the world origin is the center of the launch pad (or runway).  Once you launch the origin stays stationary for a bit.  When the ship is 500 m away the world origin jumps to the current position of the root part, but stays stationary in world space. When you are 500 m away, it repeats. If you revert to the launchpad the origin begins at the root part instead of on the launch pad, but all else stays the same.  In either case the process repeats until the ship is 150 m above the ground, at which point the world origin moves the the position of the root parts and stays there.  The position of the ship is the location of the center of mass

I had originally said it was the command node and center of mass and had which was origin and which was position backwards. I was also able to determine when the switching happens. I have screen shots but I can't them to upload.

Edited by archer1572
Corrections and additions
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...