Search the Community
Showing results for tags 'interpolation'.
-
Hi, in order to implement a safer interpolation mechanism on LMP I store the orbital positions in a queue and replay them after 2 seconds have passed. The code looks something like this: var startTime = KspOrbit.epoch; var targetTime = Target.KspOrbit.epoch; var currentPos = KspOrbit.getRelativePositionAtUT(startTime); var targetPos = Target.KspOrbit.getRelativePositionAtUT(targetTime); var currentVel = KspOrbit.getOrbitalVelocityAtUT(startTime) + KspOrbit.referenceBody.GetFrameVelAtUT(startTime) - Body.GetFrameVelAtUT(startTime); var targetVel = Target.KspOrbit.getOrbitalVelocityAtUT(targetTime) + Target.KspOrbit.referenceBody.GetFrameVelAtUT(targetTime) - Target.Body.GetFrameVelAtUT(targetTime); var lerpedPos = Vector3d.Lerp(currentPos, targetPos, LerpPercentage); var lerpedVel = Vector3d.Lerp(currentVel, targetVel, LerpPercentage); Vessel.orbit.UpdateFromStateVectors(lerpedPos, lerpedVel, LerpBody, Planetarium.GetUniversalTime()); KSPOrbit is the first packet Orbit, Target.KSPOrbit is the next packet, and on every fixed update frame that code is called. In order to ignore FlightIntegration issues I only call this when vessels are PACKED (OnRails) (I will deal with FI later) The LerpPercentage is a value between 0 and 1 that increases on every fixedupdate call The movement is very fluid BUT the positions are displaced kind of "backwards" This is for example a screenshot I took with 2 clients side by side: Here the player 1 is flying above that wide line in the runway: https://imgur.com/0oPcYHH But the player 2 sees this: https://imgur.com/HlEmoxJ I understand the GREEN distance as the vessel is 2 seconds behind and it will take some time to reach the runway but I don't understand why it's displaced sideways (red distance) Also, I tried to set this code: var lerpTime = LunaMath.Lerp(startTime, targetTime, LerpPercentage); Vessel.orbit.UpdateFromStateVectors(lerpedPos, lerpedVel, LerpBody, lerpTime); But then the orbit is rendered in real time (not 2 seconds behind in time) and the vessel goes inside Kerbin a lot of times and there are weird movements. I think there's some orbital calculation that I'm missing but I can't find how should I proceed on this... I even tried specifying the position manually as: Vector3d vector3d = Vessel.orbitDriver.driverTransform.rotation * Vessel.localCoM; Vessel.SetPosition((planetPos + Vessel.orbitDriver.pos) - vector3d); But I didn't had luck Does someone have an idea of how I should implement this? It's honestly one of the oldest LMP bugs and I've been dealing with this for months and not making much progress. EDIT: If I reduce the interpolation delay time to 300ms or so the movement is almost perfect (there's still that sideway distance altough much shorter) but I want to set a 1 or 2 seconds delay for bad connections
- 12 replies
-
- interpolation
- orbit
-
(and 2 more)
Tagged with: