Fix explosion animation on upside down area

This commit is contained in:
Benau
2016-09-29 14:37:39 +08:00
parent 43c40c062e
commit d386c76e2d
2 changed files with 9 additions and 5 deletions

View File

@@ -77,6 +77,7 @@ ExplosionAnimation::ExplosionAnimation(AbstractKart *kart,
{
m_xyz = m_kart->getXYZ();
m_orig_xyz = m_xyz;
m_normal = m_kart->getNormal();
m_kart->playCustomSFX(SFXManager::CUSTOM_EXPLODE);
m_timer = m_kart->getKartProperties()->getExplosionDuration();
@@ -141,11 +142,10 @@ ExplosionAnimation::~ExplosionAnimation()
void ExplosionAnimation::update(float dt)
{
m_velocity -= dt*World::getWorld()->getTrack()->getGravity();
Vec3 normal = -1.0f*m_kart->getBody()->getGravity().normalized();
m_xyz = Vec3(m_xyz + dt*m_velocity*normal);
m_xyz = m_xyz + dt*m_velocity*m_normal;
// Make sure the kart does not end up under the track
if ((m_xyz - m_orig_xyz).dot(normal)<0)
if ((m_xyz - m_orig_xyz).dot(m_normal)<0)
{
m_xyz = m_orig_xyz;
// This will trigger the end of the animations

View File

@@ -37,14 +37,18 @@
class ExplosionAnimation: public AbstractKartAnimation
{
protected:
/** The coordinates where the kart was hit originally. */
/** The coordinates where the kart was hit originally, it will be increased
* later. */
Vec3 m_xyz;
/** The original Y coordinate. The kart needs to be restored accurately
/** The original coordinates. The kart needs to be restored accurately
* otherwise due to floating point errors, time step size variations,
* a kart can be restarted under the track. */
Vec3 m_orig_xyz;
/** The normal of kart when it started to explode. */
Vec3 m_normal;
/** The kart's current rotation. */
Vec3 m_curr_rotation;