Second, collision detection and response are two different things. Quite obviously your detection works. Now you need to figure out how to respond to the collision. Basic response is easy, don't do anything (besides not letting the player move in the direction of the block of course!). I have found a couple of issues with your code, I believe.

First, the casting thing. Are you seriously telling me the player positions are limited to the range of a byte?

Second, you shouldn't be checking for each key combination. What you need to do is every frame you need to find where the player will be next. That means you will need some variables:

Movespeed - obvious what it isPosition - Player positionNext direction - basically on what axis will the player be moving next?

Then, use the following formula to calculate the next position of the player:

No. AABBs are just a form of collision detection. It stands for Axis Aligned Bounding Box because the boxes never rotate. More specifically the model axis always line up with the world axis. If they did rotate you would have to use something like SAT.

You aren't using AABBs right now, you're just checking to see if you are going to be inside a block space. Its completely different.

Ah yes. Well, think about it. Your blocks are in an array, and arrays have indices. 1, 2, 3... Etc... So, it you want to get the next position of your player relative to your block array, you need to access the next block in which you are going to move. So, logically nextPos would only hold a value of 1 or 0 for its components.

What that's means is that when you hit 'W' for example, you want to move forward on the Z axis. So, you set nextPos.z to be 1. Then you move the player. After you have moved the player, do two collision detection checks. Like this:

1 2 3

if(Game.world.getBlock(pos.x + nextPos.x * moveSpeed, pos.x, pos.z) != null) {//do collision response for x axis. In this case, you can simply not move the player. Repeat this if statement for the y and z axis accordingly. You must check each axis separately though.}

Pretty simple really, and you don't need all those if statements that you already have. Just three simple if statements.

You have to calculate the velocity of your players bounding-box into the given Voxels bounding-box you are checking for collision, reducing the velocity on each axis for every voxel-collision so you don't go trough any block.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org