From d7071bfab2bc630186af5da2ae947499594d11a4 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Wed, 21 Mar 2012 21:01:11 +0000 Subject: [PATCH] Improved AI's handling of push back that now happens after a kart - track collision: AI karts will now steer towards the center of the track while being pushed back. While this does not fully fix #576, it improves the situation in many cases. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11004 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- .../controller/default_ai_controller.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/karts/controller/default_ai_controller.cpp b/src/karts/controller/default_ai_controller.cpp index ab1aae536..a18cebb1f 100644 --- a/src/karts/controller/default_ai_controller.cpp +++ b/src/karts/controller/default_ai_controller.cpp @@ -364,11 +364,24 @@ void DefaultAIController::handleSteering(float dt) *finite state machine. */ //Reaction to being outside of the road - if( fabsf(m_world->getDistanceToCenterForKart( m_kart->getWorldKartId() )) > + float side_dist = + m_world->getDistanceToCenterForKart( m_kart->getWorldKartId() ); + if( fabsf(side_dist) > 0.5f* QuadGraph::get()->getNode(m_track_node).getPathWidth()+0.5f ) { - steer_angle = steerToPoint(QuadGraph::get()->getQuadOfNode(next) - .getCenter()); + // If the speed is negative, the kart is most likely being pushed + // away from a collision with the terrain, and this most likely means + // that the kart is off track. In this case, steer so that the kart + // will rotate towards the center of the track. E.g. if the kart is + // to the right, steer towards the right. + if(m_kart->getSpeed()<0) + { + steer_angle = side_dist > 0 ? -m_kart->getMaxSteerAngle() + : m_kart->getMaxSteerAngle(); + } + else + steer_angle = steerToPoint(QuadGraph::get()->getQuadOfNode(next) + .getCenter()); #ifdef AI_DEBUG m_debug_sphere->setPosition(QuadGraph::get()->getQuadOfNode(next)