Well I have a question about geometry and 3-Dimensional player movement in general. I'm using Java, OpenGL and LWJGL.
This is basically what I got:
- currentFrontSpeed: Is a float that contains the speed of the Player.
player. increasePosition: Just adds the current Position of the Player to the value that is given on the X, Y and Z axis.
//The point we want to go: Forwards(+) Backwards(-). getFrameTimeSeconds //just adjust the speed depending of the speed of the computer. float distanceFront = currentFrontSpeed * DisplayManager.getFrameTimeSeconds(); //Distance of Movement float fx = (float) (distanceFront * Math.sin(Math.toRadians(player.getRotY()))); float fz = (float) (distanceFront * Math.cos(Math.toRadians(player.getRotY()))); //This just increase the position of the player (x,y,z) player.increasePosition(fx, 0, fz);
Another thing that I didn't explained is that the Player is always looking at the same position as the camera (if the camera turns to the right, the player would also turn to the right. Like Maincraft). That's why I use the Y-Axis to move.
The problem is that my player can only move forwards and backwards (if currentFrontSpeed is positive, my player will move FORWARDS, and if is negative BACKWARDS). And the only form to go to a place that is to the right is to move the Camera to the right and the press UP to go FORWARDS.
I've tried to achieve this doing this:
//The same as above, the speed of the player this time Right(+) and Left(-) float distanceSides = currentSideSpeed * DisplayManager.getFrameTimeSeconds(); float sx = (float) (distanceSides * Math.cos(Math.toRadians(player.getRotY()))); float sz = (float) (distanceSides * Math.sin(Math.toRadians(player.getRotY()))); //I just add the "horizontal" speed to the "vertical" one player.increasePosition(fx + sx, 0, fz + sz);
Of course this doesn't work good: if the player Y-rotation is 0, the player moves to the right and to the left perfectly; but for example, if the player rotation is 90 (looking at the right from the original position), moving up or moving to the right would take us to the same position (because is the "right" from the original position with the Y-axis 0).
I don't know if I should use another trigonometric function or add the sx and the sz to another value in the X, Y and Z axis.
I've just edited and gived some information because of the bad explaining I did. Also this is one of my first long-writed post.
Thanks for helping!