   collision detection problem
  We have a tile based collision system with full tiles and half-tiles. Our problem is that we cant determine the direction from which we hit the tile, for example if we hit it from above, left, right or beneath. The problem is that the inverse of cosine only returns a value from 0 to pi and not the full 360 degrees, if it did we could check the angle of the collision.Any suggestions? 
  First, I hope you are moving your guy this way: //Plus some type of code to make computer independent movement.X+= SpeedX; Y+= SpeedY;   The first function I have is: bool CMap::CollideTile(int X, int Y) {int ID = GetTileID(X, Y);if(Tile[ID].GetTypeID() == TILE_TYPE_GROUND) {return true;}return false;};   Then I have this function. void CObject::CheckTileCollisions() {int i = 0;TopTileCollision = false;BottomTileCollision = false;RightTileCollision = false;LeftTileCollision = false;if(SpeedY != 0) {for(i = 0;i < Width;i++) {if(MapControl->CollideTile(X + i, Y + SpeedY * MoveTime)) {//printf("Collision on the Top!\n");TopTileCollision = true;}}if(Y + SpeedY < 0) {TopTileCollision = true;}for(i = 0;i < Width;i++) {if(MapControl->CollideTile(X + i, Y + (Height - 1) + SpeedY * MoveTime)) {//printf("Collision on the Bottom!\n");BottomTileCollision = true;}}if(Y + (Height - 1) + SpeedY > MapControl->GetHeight()) {//printf("Collision on the Bottom!\n");BottomTileCollision = true;}}if(SpeedX != 0) {for(i = 0;i < Height;i++) {if(MapControl->CollideTile(X + SpeedX * MoveTime, Y + i)) {//printf("Collision on the Left!\n");LeftTileCollision = true;}}if(X + SpeedX < 0) {LeftTileCollision = true;}for(i = 0;i < Height;i++) {if(MapControl->CollideTile(X + (Width - 1) + SpeedX * MoveTime, Y + i)) {//printf("Collision on the Right!\n");RightTileCollision = true;}}if(X + (Width - 1) + SpeedX > MapControl->GetWidth()) {RightTileCollision = true;}}};   Hope that helps.  [edited by - MetaCipher on February 11, 2004 12:32:18 PM];  You should only be able to hit a tile on a side facing your movement vector. If you are moving up, you can only hit the bottom of a tile. If you are moving up AND right, you can hit either the left side, bottom side or both (corner).This is assuming your tiles are non-moving and your objects are all rectangular in their collision shapes. ;  to get the full angle of a segment.float dx = (x1 - x0);float dy = (y1 - y0);angle = atan2(dy, dx);that''s between -PI and PI 