Hello all,
Again, still on my 3D Shoot Game inspired from S4League but without the "s4client.exe has stopped working...", i'm trying to make my player coliding with map strcuture. The map structure on my game would be only some blocks with a defined width, height and float coords (x, y, z).
I tried everything but i can't get the player to colide with blocks on X and Z at one time. I need to choose if i want my player coliding on X axis or Z axis but can't get both axis detection.
Here is my code :
private void checkColisions(){
/*Note : My engine Player class coord system is working differently than Minecraft or some other games.
Indead everything is inversed (example y + 2 should be y - 2 to make player moving up of 2 units)
Same for X coord and Z coord.
*/
//position = Vector3f of the player position in world.
float x = thePlayer.position.x;
float z = thePlayer.position.z;
float y = thePlayer.position.y;
for (Block b : mapStructure){
if (b != null) {
if (x <= (b.x * -1) && x >= ((b.x * -1) - b.width)) {
if (z <= (b.z * -1) && z >= ((b.z * -1) - b.width)) {
//Just a test to be sure engine knows how to kill a player : yes he knows ! I can die oh yay !!
//thePlayer.decreaseHealth(0.001F);
if(x <= (b.x * -1) && x > ((b.x * -1) - 0.1)){
thePlayer.position.x = (b.x * -1);
} else if (x >= ((b.x * -1) - b.width) && x > (((b.x * -1) - b.width) - 0.1)){
thePlayer.position.x = ((b.x * -1) - b.width);
}
if (z <= (b.z * -1) && z > ((b.z * -1) - 0.1)){
thePlayer.position.z = (b.z * -1);
} else if (z >= ((b.z * -1) - b.width) && z > (((b.z * -1) - b.width) - 0.1)){
thePlayer.position.z = ((b.z * -1) - b.width);
}
}
}
}
}
}