improved aiming of cakes by using the heading vector instead of the velocity vector

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2380 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2008-10-25 19:41:45 +00:00
parent 7b5aeaaac2
commit 66e12f795a

View File

@ -146,14 +146,19 @@ void Flyable::getClosestKart(const Kart **minKart, float *minDistSquared,
if(inFrontOf != NULL)
{
// Ignore karts behind the current one
btVector3 to_target = inFrontOf->getXYZ()-kart->getXYZ();
btVector3 to_target = kart->getXYZ() - inFrontOf->getXYZ();
const float distance = to_target.length();
if(distance > 50) continue; // kart too far, don't aim at it
float angle = to_target.angle(-inFrontOf->getVelocity());
btTransform trans = inFrontOf->getTrans();
// get heading=trans.getBasis*(0,1,0) ... so save the multiplication:
btVector3 direction(trans.getBasis()[0][1],
trans.getBasis()[1][1],
trans.getBasis()[2][1]);
float angle = to_target.angle(direction);
if(fabsf(angle) > 1) continue;
}
if(distance2 < *minDistSquared || *minDistSquared < 0 /* not yet set */)