Movement without Physics, a collision problem

How is the Data of the Terrain stored?

If it's somekind of heightmap, you can use that as a beginning…

And what should happen if it collide with the terrain side by side?

The terrain is generated from a heightmap (heightMap.png), but the actual terrain Blocks are stored in a 3-dimensional array.

When the player has a side on side collision with the terrain, I would like for the player not to enter the terrain. Some way for me to detect the direction of the collision allowing me to move the player in the opposite direction would work, but I don’t know how to go about doing that.

So, you have a 3D array of boxes?

And each box is of equal width isn't it?

I assume the box locations are all Vector3f with positive x, y, and z.

So:

``` .. boolean[][][] boxes; // if there is a box or not. if you use a Mesh[][][] array, or sth like this, just use == null Vector3f boxExtent = ...; // these are real extents, not half ones. Vector3f playerLocation = player.getWorldTranslation(); boolean[][] collisions = new boolean[3][2]; // 2 possible collisions per axis. // add one because in the conversion to int, the numbers after the digit will be lost int x = playerLocation.x/boxExtent.x +1; int y = playerLocation.y/boxExtent.y +1; int z = playerLocation.z/boxExtent.z +1; // if this assertion fails, my code snippet was wrong  assert !boxes[x][y][z] : "The player should never be _in_ a Box"; if(boxes[x-1][y][z])         collisions[0][0] = true; else if(boxes[x+1][y][z]) collisions[0][1] = true; if(boxes[x][y-1][z])         collisions[1][0] = true; else if(boxes[x][y+1][z]) collisions[1][1] = true; if(boxes[x][y][z-1])         collisions[2][0] = true; else if(boxes[x][y][z+1]) collisions[2][1] = true; // so now, the collisions array should contain all collisions. // e.g. if collisions[axis][i] is false, you can't move it forward (if i is 1) or backward (if i is 0) on the axis (0 is X, 1 is Y, 2 is Z) ```

This may not work perfectly, but it should point you in the right direction.
Btw.. ever thought of using Octrees, to organize your scene?

Wow, that's an amazingly good idea! If I can get that to work correctly, it will be much faster that doing the built in collision detection, and should work with all the features I have planned. Thanks!

(To answer your question, I do have an octree of sorts. The world is loaded as a series of 64*64 tiles from the above heightmap.)

Thank you!

For finding a good solution you often have to go the other way round

Please report if you got it working!

Ah okay, so, you have to care to always use the right tile for collision checking… but shouldn't be hard though.