From 66e12f795a8c937dce40aad8b1a2915fffe2d90a Mon Sep 17 00:00:00 2001 From: auria Date: Sat, 25 Oct 2008 19:41:45 +0000 Subject: [PATCH] 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 --- src/flyable.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/flyable.cpp b/src/flyable.cpp index c4a920d6a..d640912af 100644 --- a/src/flyable.cpp +++ b/src/flyable.cpp @@ -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 */)