Avoid negative square root

Which seems to happen if a kart is going backward
This commit is contained in:
Benau 2016-05-03 15:44:44 +08:00
parent a852c9857e
commit bf64ce9ec0

View File

@ -317,7 +317,14 @@ void Flyable::getLinearKartItemIntersection (const Vec3 &origin,
* (dx * cosf(target_kart_heading) -
dz * sinf(target_kart_heading) );
float fire_th = (dx*dist - dz * sqrtf(dx*dx + dz*dz - dist*dist))
float f = dx*dx + dz*dz - dist*dist;
// Avoid negative square root
if(f>0)
f = sqrtf(f);
else
f = 0.0f;
float fire_th = (dx*dist - dz * f)
/ (dx*dx + dz*dz);
if(fire_th>1)
fire_th = 1.0f;