Smooth other-player movement with velocity dead reckoning

Previously other players jittered because the entity sat frozen at its
destination between movement packets, then snapped to the new start
position on the next packet (stop-pop-stop-pop at ~10 Hz).

Entity interpolation now tracks a smoothed velocity and dead-reckons
past the end of each packet window, so the entity keeps gliding at the
estimated speed until the next server update arrives. Movement stops
only after two consecutive intervals with no new packet (entity has
genuinely stopped).

Also replaced the raw packet-delta duration with an exponential moving
average (EMA) per player. A single slow or fast packet no longer spikes
the playback speed; the EMA converges on the actual send rate (~100 ms)
and absorbs jitter without adding a fixed input-latency penalty.
This commit is contained in:
Kelsi 2026-02-19 16:45:39 -08:00
parent 2bbd0fdc5f
commit d7692ab88e
3 changed files with 50 additions and 12 deletions

View file

@ -7641,15 +7641,23 @@ void GameHandler::handleOtherPlayerMovement(network::Packet& packet) {
// Convert server coords to canonical
glm::vec3 canonical = core::coords::serverToCanonical(glm::vec3(info.x, info.y, info.z));
float canYaw = core::coords::serverToCanonicalYaw(info.orientation);
// Smooth movement between client-relayed snapshots so animations can play.
uint32_t durationMs = 100;
// Compute a smoothed interpolation window for this player.
// Using a raw packet delta causes jitter when timing spikes (e.g. 50ms then 300ms).
// An exponential moving average of intervals gives a stable playback speed that
// dead-reckoning in Entity::updateMovement() can bridge without a visible freeze.
uint32_t durationMs = 120;
auto itPrev = otherPlayerMoveTimeMs_.find(moverGuid);
if (itPrev != otherPlayerMoveTimeMs_.end()) {
uint32_t dt = info.time - itPrev->second; // handles wrap
if (dt >= 30 && dt <= 1000) {
if (dt < 50) dt = 50;
if (dt > 350) dt = 350;
durationMs = dt;
uint32_t rawDt = info.time - itPrev->second; // wraps naturally on uint32_t
if (rawDt >= 20 && rawDt <= 2000) {
float fDt = static_cast<float>(rawDt);
// EMA: smooth the interval so single spike packets don't stutter playback.
auto& smoothed = otherPlayerSmoothedIntervalMs_[moverGuid];
if (smoothed < 1.0f) smoothed = fDt; // first observation — seed directly
smoothed = 0.7f * smoothed + 0.3f * fDt;
// Clamp to sane WoW movement rates: ~10 Hz (100ms) normal, up to 2Hz (500ms) slow
float clamped = std::max(60.0f, std::min(500.0f, smoothed));
durationMs = static_cast<uint32_t>(clamped);
}
}
otherPlayerMoveTimeMs_[moverGuid] = info.time;