diff --git a/src/flyable.hpp b/src/flyable.hpp index 5dd56eee9..f431544cf 100644 --- a/src/flyable.hpp +++ b/src/flyable.hpp @@ -102,7 +102,7 @@ public: virtual void hitTrack () {}; void explode (Kart* kart, MovingPhysics* moving_physics=NULL); - bool hasHit () { return m_has_hit_something; } + bool hasHit () { return m_has_hit_something; } void reset () { Moveable::reset(); } }; // Flyable diff --git a/src/items/plunger.hpp b/src/items/plunger.hpp index c0a2b1c42..ce8ec0e87 100644 --- a/src/items/plunger.hpp +++ b/src/items/plunger.hpp @@ -33,7 +33,8 @@ public: ~Plunger(); static void init (const lisp::Lisp* lisp, ssgEntity* missile); virtual void update (float dt); + virtual void hitTrack () { explode(NULL); } -}; // Missile +}; // Plunger #endif diff --git a/src/items/rubber_band.cpp b/src/items/rubber_band.cpp index 2c14375d0..1148f5b55 100755 --- a/src/items/rubber_band.cpp +++ b/src/items/rubber_band.cpp @@ -86,27 +86,29 @@ void RubberBand::removeFromScene() */ void RubberBand::update(float dt) { - const Vec3 &p=m_plunger->getXYZ(); - const Vec3 &k=m_kart.getXYZ(); + // Don't do anything for plungers who already hit something. + if(m_plunger->hasHit()) return; - Vec3 diff=p-k; + const Vec3 &p = m_plunger->getXYZ(); + const Vec3 &k = m_kart.getXYZ(); - // See if anything hits the rubber band, but only if there is a certain - // distance between plunger and kart. Otherwise the raycast will either - // hit the kart or the plunger. - if(diff.length2()>2.0f) + btCollisionWorld::ClosestRayResultCallback ray_callback(k, p); + // Disable raycast collision detection for this plunger and this kart! + short int old_plunger_group = m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup; + short int old_kart_group = m_kart.getBody()->getBroadphaseHandle()->m_collisionFilterGroup; + m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0; + m_kart.getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0; + + // Do the raycast + RaceManager::getWorld()->getPhysics()->getPhysicsWorld()->rayTest(k, p, + ray_callback); + // Reset collision groups + m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_plunger_group; + m_kart.getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_kart_group; + if(ray_callback.HasHit()) { - diff.normalize(); - const Vec3 from=k+diff; // this could be made dependent on kart length - const Vec3 to = p-diff; - btCollisionWorld::ClosestRayResultCallback ray_callback(from, to); - RaceManager::getWorld()->getPhysics()->getPhysicsWorld()->rayTest(from, - to, ray_callback); - if(ray_callback.HasHit()) - { - m_plunger->explode(NULL); - return; - } + m_plunger->explode(NULL); + return; } // Otherwise set the new coordinates for the plunger and the kart: