Hi, I'm making a simple game, but I have problems with my collision detection! My world is based on tiles with currently four different types: FLOOR, WALL, VOID and PIT.
You shouldn't be able to walk over WALL or VOID and you should only be able to get over PIT if you're jumping! Here's my problem:
It miscalculates wich type of tile I am actually standing on! For example:
If I'm standing on a FLOOR Tile it may say that I'm standing on an VOID tile 3 tiles away, but it isn't that it calculates each void tile 1 tile away from the actual tile, It doesn't have that kind of pattern!
This is my code that checks if a player can be on a specified tile or not:
Code java:public boolean canBeAt(Entity par0Entity, int par1, int par2) { int var0 = (int) Math.floor((par1 / 32)); int var1 = (int) Math.floor((par2 / 32)); //System.out.println(var0 + " " + var1); Tile var2 = world[var0][var1]; TileType var3 = var2.getType(); System.out.println(var3); if (var3 == TileType.VOID || var3 == TileType.WALL) return false; if (var3 == TileType.PIT && par0Entity.isInContactWithGround()) return false; return true; } public BufferedImage getTexture(int par0) { return tileTextures[par0]; }
Since my tiles are 32*32 and since my tiles are stored in a Tile[][] were the first bracket is the y axis and the second is the x axis I thought i would do like this:
Divide the players x axis(par1) with 32 then floor the value into an integer and use this as the x axis in the Tile array, then do the same thing with the player y axis(par2), but for some reason I cant explain
it doesn't work!
Please help me!

