Jump to content

Update vessel position at every frame


Recommended Posts

Hi, I'm doing a fork of DMP and I'm having problems when updating a vessel position.

The idea is that aproximately every 30ms I receive a message with a vessel position, I store it in a buffer and I apply it on the fixedupdate to the corresponding vessel in a way that I always have 1 packet in the buffer (otherwise the vessel would stop moving until I receive the next one and the movement would jitter)

Between those 30ms between packets I interpolate the vessel position with the function Lerp. but still, when flying in formation and at high speeds the vessel jitters and "jumps" in it's movement, even if it's packed or unpacked.

Here is the code that I use for the vessel positioning.

 

private void ApplySurfaceInterpolation(float interpolationValue)
{
	//interpolationValue is a value between 0 and 1 to do the Lerp logic.
	//Velocity components are sent as vessel.rb_velocityD
      var currentVelocity = GetInterpolatedVelocity(interpolationValue, currentAcc);

      Vessel.latitude = Lerp(LatLonAlt[0], Target.LatLonAlt[0], interpolationValue);
      Vessel.longitude = Lerp(LatLonAlt[1], Target.LatLonAlt[1], interpolationValue);
      Vessel.altitude = Lerp(LatLonAlt[2], Target.LatLonAlt[2], interpolationValue);
      var worldSurfacePosition = Vessel.mainBody.GetWorldSurfacePosition(Vessel.latitude, Vessel.longitude, Vessel.altitude);

      var startWorldPos = new Vector3d(WorldPosition[0], WorldPosition[1], WorldPosition[2]);
      var targetWorldPos = new Vector3d(Target.WorldPosition[0], Target.WorldPosition[1], Target.WorldPosition[2]);
      var currentWorldPos = Vector3d.Lerp(startWorldPos, targetWorldPos, interpolationValue);

      Vessel.SetPosition(worldSurfacePosition, true);
      Vessel.CoMD = currentWorldPos;

      var startOrbitPos = new Vector3d(OrbitPosition[0], OrbitPosition[1], OrbitPosition[2]);
      var targetOrbitPos = new Vector3d(Target.OrbitPosition[0], Target.OrbitPosition[1], Target.OrbitPosition[2]);
      var currentOrbitPos = Vector3d.Lerp(startOrbitPos, targetOrbitPos, interpolationValue);
      Vessel.orbit.pos = currentOrbitPos;

      Vessel.SetWorldVelocity(currentVelocity);
}

Is there something I'm missing or some other vessel position variable that I must send?

Edited by Dagger
Link to comment
Share on other sites

Hey. I could not reply to your IRC message since you were gone by the time I was online.

Moving a vessel by hand is actually quite complex in 1.2 and the call to make it easier are only meant to move the active vessel...

The problem is that you are fighting the orbit and flight integrator code and you set things you should not set by hand (CoMD is not at the position,orbit.pos should be computed by the oribit code). I am at work so my reply will be from memory (with the help of the API site) but if you want to move those vessel yourself (since they position are from a remote host) you should make sure all the stock position / movement system are off (at least I would do it that way, I may be missing an obvious problem to that).

So I would set the vessel to on rail and set its OrbitDriver  updateMode  to IDLE. That should solve some of your problem. But I don't know how DMP handle remote vessel so it may require a lot more like disabling most vessel components.

SetPosition & SetWorldVelocity are only relevant on packed vessels.

Link to comment
Share on other sites

Hi sarbian, thanks a lot for your answer.

I changed the code so all the other player controlled vessels are packed (by editing the vesselRanges) and it seems much better and smooth :)

 

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