I find this to be very useful, if you want a player to collide with something, instead of checking if the players position is at the objective position, you can calculate the distance from the player and the objective, if its less than 1, do codes, I'm not sure if this works in C++, but I've tryed and came here to check with you guyz if it, because I some errors
Code: Select all
??? Distance2D( int x1, int y1, int x2, int y2 );
{<--- ?
float Dist;
int X = ( x2 - x1 );
int Y = ( y2 - y1 );
Dist = sqrt( (X*X) + (Y*Y ));
return Dist;
}
??? = Don't really know what to put there, void won't work because void is when you don't return any value, but in this case you must return the distance value.
<--- ? = error c2447: '{' : missing function header (old-style format list?)