Jump to content

Displayed graphic is jumping when rover gets too far


Recommended Posts

I'm working on reviving RoverScience.  There is an old bug where if you get too far away (about 400m or so) from the displayed science dome, the location of the dome jumps.  I believe this is due to the reference coordinates changing as the rover moves over the planet surface.

I tried adding this code:

void Start()
{
	 GameEvents.onVesselReferenceTransformSwitch.Add(UpdateMarkerPositionInvoked);
}
        void UpdateMarkerPositionInvoked(Transform t1, Transform t2)
        {
            DrawWaypoint.Instance.SetMarkerLocation(RoverScience.Instance.rover.scienceSpot.location.longitude, RoverScience.Instance.rover.scienceSpot.location.latitude, spawningObject: false);
        }


        public void SetMarkerLocation(double longitude, double latitude, bool spawningObject = true)
        {
            DestroyInterestingObject();

            Vector3 bottomPoint = FlightGlobals.currentMainBody.GetWorldSurfacePosition(latitude, longitude, 0);
            Vector3 topPoint = FlightGlobals.currentMainBody.GetWorldSurfacePosition(latitude, longitude, 1000);

            double surfaceAltitude = GetSurfaceAltitude(longitude, latitude);
            marker.transform.position = FlightGlobals.currentMainBody.GetWorldSurfacePosition(latitude, longitude, surfaceAltitude);

            marker.transform.localScale = new Vector3(markerSizeMax, markerSizeMax, markerSizeMax);
            markerRed.a = maxAlpha;

       }

but it seems that the gameevent I am trying to use isn't the right one.

For now, I added the following which works, but obviously isn't the best:

void Start()
{
	InvokeRepeating("UpdateMarkerPosition", 0.1f, 0.1f);
}

void UpdateMarkerPosition()
{
	DrawWaypoint.Instance.SetMarkerLocation(RoverScience.Instance.rover.scienceSpot.location.longitude, RoverScience.Instance.rover.scienceSpot.location.latitude, spawningObject: false);
}

 

So how do I find out when the reference coordinates change?  

Link to comment
Share on other sites

onVesselReferenceTransformSwitch is for when the "control from here" part is modified, this is indeed unlikely to help in any way.

You could try offsetting the marker.transform.position by the value returned by GameEvent. onFloatingOriginShift, by I have some doubts this will work.

The best way to make things work is likely to have your marker object a child object of the local CelestialBody, instead of having it floating around in world space.

Link to comment
Share on other sites

4 hours ago, Gotmachine said:

onVesselReferenceTransformSwitch is for when the "control from here" part is modified, this is indeed unlikely to help in any way.

You could try offsetting the marker.transform.position by the value returned by GameEvent. onFloatingOriginShift, by I have some doubts this will work.

The best way to make things work is likely to have your marker object a child object of the local CelestialBody, instead of having it floating around in world space.

Thanks, I'll have to look at that.  This is an old mod, while I've gotten it working, there were open bugs and a lot of inefficiencies there.  I'll look at the code to see if I can do that easily, otherwise what I have does does, just not the best way to do it

Currently this is the code that creates the object:

            marker = GameObject.CreatePrimitive(PrimitiveType.Sphere);

I'll have to figure out how to create it as a child of the local celestial body

 

Edit:

@GotmachineWould this do it:

            marker = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            marker.transform.parent = FlightGlobals.ActiveVessel.mainBody.transform;

 

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