diff --git a/src/karts/ghost_kart.cpp b/src/karts/ghost_kart.cpp index bcb12dda4..8ec4e8883 100644 --- a/src/karts/ghost_kart.cpp +++ b/src/karts/ghost_kart.cpp @@ -130,12 +130,19 @@ void GhostKart::update(int ticks) const float rd = gc->getReplayDelta(); assert(idx < m_all_transform.size()); - setXYZ((1- rd)*m_all_transform[idx ].getOrigin() - + rd *m_all_transform[idx + 1].getOrigin() ); - - const btQuaternion q = m_all_transform[idx].getRotation() - .slerp(m_all_transform[idx + 1].getRotation(), rd); - setRotation(q); + if (idx >= m_all_transform.size() - 1) + { + setXYZ(m_all_transform.back().getOrigin()); + setRotation(m_all_transform.back().getRotation()); + } + else + { + setXYZ((1- rd)*m_all_transform[idx ].getOrigin() + + rd *m_all_transform[idx + 1].getOrigin() ); + const btQuaternion q = m_all_transform[idx].getRotation() + .slerp(m_all_transform[idx + 1].getRotation(), rd); + setRotation(q); + } Moveable::updatePosition(); float dt = stk_config->ticks2Time(ticks); @@ -235,8 +242,8 @@ float GhostKart::getSpeed() const assert(gc->getCurrentReplayIndex() < m_all_physic_info.size()); - if (current_index == m_all_physic_info.size()) - return m_all_physic_info[current_index].m_speed; + if (current_index >= m_all_physic_info.size() - 1) + return m_all_physic_info.back().m_speed; return (1-rd)*m_all_physic_info[current_index ].m_speed + rd *m_all_physic_info[current_index + 1].m_speed;