15.10.2012, 10:58
Emmet for this function
You could use the absolute power function...
Like this:
pawn Code:
stock Float:getdistance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
new Float:distance[3];
distance[0] = (x1 < x2) ? x1 - x2 : x2 - x1;
distance[1] = (y1 < y2) ? y1 - y2 : y2 - y1;
distance[2] = (z1 < z2) ? z1 - z2 : z2 - z1;
return floatsqroot(floatpower(distance[0], 2.0) + floatpower(distance[1], 2.0) + floatpower(distance[2], 2.0));
}
Like this:
pawn Code:
Distance = floatsqroot(floatpower(floatabs(floatsub(X1, X2)), 2.0) + floatpower(floatabs(floatsub(Y1, Y2)), 2.0) + floatpower(floatabs(floatsub(Z1, Z2)), 2.0));