the floor is the block that im stood on, so there is just the chunk, and the floor is found by litterally dropping out of the sky and landing on a block.
so if a block is 8 high, the floor is 9 in my game. the floor is not drawn,its just the block. here is my code to calculate that.
private void updateLogic() {
ground = getGroundLevel(xpos, playerheight, zpos);
playerheight+=yVelocity*TIME_STEP;
yVelocity+=GRAVITY*TIME_STEP;
if(playerheight<=ground) {
isJumping = false;
yVelocity=0;
playerheight= ground;
}
}
my get ground level method is this:
int groundLevel=y;
//System.out.println("ground level = " + groundLevel);
for(int gl = groundLevel;y>-1;y--){ //cycle thorugh the blocks under the player untill we hit one;
if(chunks[c].getblockID(x, gl,z)>0)return gl;
}
this is how I jump
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
if(!isJumping){
isJumping= true;
yVelocity=6f;
}
}
Setup:
float yVelocity=0.0f;
final double TIME_STEP=1/60.0;
final float GRAVITY=-11f;
Before I render the VBO chunks:
//position the player/camera
GL11.glRotatef(lookupdown, 1.0f, 0, 0);
GL11.glRotatef(360.0f - yrot, 0, 1.0f, 0);
GL11.glTranslatef(-xpos, camHieght , -zpos);
I should also mention that I add a walkbias to the cam hight to for rendering only,
I found this part in NeHe’s excellent tutorials.
walkbiasangle += 10.0f;
if (walkbiasangle > 360.0f) {
walkbiasangle -= 360.0f;
}
walkbias = (float) Math.sin(walkbiasangle * piover180) / 20.0f;
}
then I add this to the camHieght at rendertime, but it does not effect the actuall calculations for falling.