Hello, I got a bit of a problem here.
I made simple code for collision detection.
When I start the game, I fly to a block and I get stuck in the block, No errors, I just can’t move in any direction.
The colliion detection happens In the block, I can’t seem to fix it. (Im new to AABB)
Code:
if((keyUp) && (keyRight) && (!keyLeft) && (!keyDown)){
if(Game.world.getBlock((byte)this.x - 1, (byte)this.y + 1, (byte)this.z) == 0){
moveLookDir(speed * delta * 0.003F + 2, 0.0F - 2, -speed * delta * 0.003F - 2);
}
}
if((keyUp) && (keyLeft) && (!keyRight) && (!keyDown)){
if(Game.world.getBlock((byte)this.x - 1, (byte)this.y - 1, (byte)this.z) == 0){
moveLookDir(-speed * delta * 0.003F + 2, 0.0F + 2, -speed * delta * 0.003F - 2);
}
}
if ((keyUp) && (!keyLeft) && (!keyRight) && (!keyDown)) {
if(Game.world.getBlock((byte)this.x - 1, (byte)this.y, (byte)this.z) == 0){
moveLookDir(0.0F + 2, 0.0F, -speed * delta * 0.003F - 2);
}
}
if ((keyDown) && (keyLeft) && (!keyRight) && (!keyUp)) {
if(Game.world.getBlock((byte)this.x + 1, (byte)this.y - 1, (byte)this.z) == 0){
moveLookDir(-speed * delta * 0.003F - 2, 0.0F + 2, speed * delta * 0.003F - 2);
}
}
if ((keyDown) && (keyRight) && (!keyLeft) && (!keyUp)) {
if(Game.world.getBlock((byte)this.x + 1, (byte)this.y + 1, (byte)this.z) == 0){
moveLookDir(speed * delta * 0.003F - 2, 0.0F - 2, speed * delta * 0.003F - 2);
}
}
if ((keyDown) && (!keyUp) && (!keyLeft) && (!keyRight)) {
if(Game.world.getBlock((byte)this.x + 1, (byte)this.y, (byte)this.z) == 0){
moveLookDir(0.0F - 2, 0.0F, speed * delta * 0.003F - 2);
}
}
if ((keyLeft) && (!keyRight) && (!keyUp) && (!keyDown)) {
if(Game.world.getBlock((byte)this.x, (byte)this.y - 1, (byte)this.z) == 0){
moveLookDir(-speed * delta * 0.003F, 0.0F + 2, 0.0F - 2);
}
}
if ((keyRight) && (!keyLeft) && (!keyUp) && (!keyDown)) {
if(Game.world.getBlock((byte)this.x, (byte)this.y + 1, (byte)this.z) == 0){
moveLookDir(speed * delta * 0.003F, 0.0F - 2, 0.0F - 2);
}
}
if ((space) && (!shift)) {
if(Game.world.getBlock((byte)this.x, (byte)this.y, (byte)this.z + 1) == 0){
this.y += 1 * delta * 0.003F;
}
}
if (!(space) && (!shift)) {
if(Game.world.getBlock((byte)this.x, (byte)this.y, (byte)this.z - 1) == 0){
this.y -= 1 * delta * 0.003F;
}
}
/**
* this.x, this.y, this.z is the camera position.
*/
Thanks for reading.