1) If the bowling ball is too slow (i.e. stuck somewhere), make it explode.

2) If a ball has exactly speed zero, correctly set dummy speed vector. 


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2936 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-01-16 00:12:46 +00:00
parent c0ed7a5737
commit d2e45864b0

View File

@ -43,7 +43,8 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, POWERUP_BOWLING, 50.0f /* mass */)
so the player doesn't catch up with the ball
and explode by touching it */
m_speed = kart->getSpeed() + m_speed;
if(m_speed < min_speed) m_speed = min_speed;
if(m_speed < min_speed) m_speed
= min_speed;
}
createPhysics(y_offset, btVector3(0.0f, m_speed*2, 0.0f),
@ -106,23 +107,22 @@ void Bowling::update(float dt)
// the ball is too high, it is 'pushed down', which can reduce the
// speed, which causes the speed to increase, which in turn causes
// the ball to fly higher and higher.
btVector3 v=m_body->getLinearVelocity();
btTransform trans=getTrans();
float hat = trans.getOrigin().getZ();
btTransform trans = getTrans();
float hat = trans.getOrigin().getZ();
btVector3 v = m_body->getLinearVelocity();
float vlen = v.length2();
if (hat<= m_max_height)
{
float vlen = v.length2();
if(vlen<0.8*m_speed*m_speed)
{ // bowling lost energy (less than 80%), i.e. it's too slow - speed it up:
if(vlen==0.0f) {
v = btVector3(.5f, .5f, 0.0f); // avoid 0 div.
}
else
{
m_body->setLinearVelocity(v*m_speed/sqrt(vlen));
}
m_body->setLinearVelocity(v*m_speed/sqrt(vlen));
} // vlen < 0.8*m_speed*m_speed
} // hat< m_max_height
if(vlen<0.1)
hit(NULL);
} // update
// -----------------------------------------------------------------------------