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
This commit is contained in:
hikerstk 2012-03-21 21:01:11 +00:00
parent 474856dbed
commit d7071bfab2

View File

@ -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)