Hello I got a lil problem.
I made a camera class and added AABB.
AABB on the Y axis works.
AABB on the X and Z axis don’t.
I can walk into a block, at each side (Except up and down (Y Axis)), I tried many things and idk how to fix.
When walking on a block its OK. When walking to a block. I can get inside and it pushes me down inside the world.
The world is empty from the inside because it’s not visible so not rendered (Face checking for more fps).
Y Axis Code:
if(space && !shift){
if(Game.world.getBlock(this.x, this.y - 3, this.z) != null){
this.y -= 0F;
}else{
this.y += speed * delta * 0.003F;
}
}else if(!space && !shift){
if(Game.world.getBlock(this.x, this.y - 3, this.z) != null){
this.y += 0F;
}else{
this.y -= (speed / 8) * 1F;
}
}
X And Z Axis Code:
if((keyUp)){
if(Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z) != Block.air && Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z) == null && !Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z).isOpaque() || Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2) != Block.air && Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2) == null && !Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2).isOpaque()) {
moveLookDir(0.0F, 0.0F, -1.0F);
}else{
moveLookDir(0.0F, 0.0F, -speed * delta * 0.003F);
}
}
if((keyDown)){
if(Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z) != Block.air && Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z) == null && !Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z).isOpaque() || Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2) != Block.air && Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2) == null && !Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2).isOpaque()) {
moveLookDir(0.0F, 0.0F, -1.0F);
}else{
moveLookDir(0.0F, 0.0F, speed * delta * 0.003F);
}
}
if((keyRight)){
if(Game.world.getBlock((int)this.x, (int)this.y, (int)this.z - 2) != Block.air && Game.world.getBlock((int)this.x, (int)this.y, (int)this.z - 2) == null && !Game.world.getBlock((int)this.x, (int)this.y, (int)this.z - 2).isOpaque() || Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2) != Block.air && Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2) == null && !Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2).isOpaque()) {
moveLookDir(-1.0F, 0.0F, 0.0F);
}else{
moveLookDir(speed * delta * 0.003F, 0.0F, 0.0F);
}
}
if((keyLeft)){
if(Game.world.getBlock((int)this.x, (int)this.y, (int)this.z - 2) != Block.air && Game.world.getBlock((int)this.x, (int)this.y, (int)this.z - 2) == null && !Game.world.getBlock((int)this.x, (int)this.y, (int)this.z - 2).isOpaque() || Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2) != Block.air && Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2) == null && !Game.world.getBlock((int)this.x - 2, (int)this.y, (int)this.z - 2).isOpaque()) {
//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.
moveLookDir(-1.0F, 0.0F, 0.0F);
}else{
moveLookDir(-speed * delta * 0.003F, 0.0F, 0.0F);
}
}
I hope someone can help me.
If u need more detail or code tell me.
Thanks for reading