Hi, I have been trying to create a first person controller and I have the mouse look perfectly well, but how do I walk in the direction relative to the players yaw? I have used this code here and it doesn't seem to work.
public void walkForward(float distance)
{
position.x -= distance * (float)Math.sin(Math.toRadians(yaw));
position.z += distance * (float)Math.cos(Math.toRadians(yaw));
}
NOTE - distance is mouseSensitivity * deltaTime
It should be this:
float speed = 0.175f */change to the speed you want in your game/* * delta;
public void walkForward() {
position.x -= (float) (Math.sin(Math.toRadians(yaw)) * speed)
position.z += (float) (Math.cos(Math.toRadians(yaw)) * speed)
}
Where speed is the units of movement you want per frame. Mouse sensitivity shouldn't control how fast the player moves.
Thank you so much!
Sorry for hijacking this thread, but what should I add to the y-Coordinate if I wanted to have a free-moving camera in every direction (like a spectator)?
So to add in a pitch:
float speed = 0.175f */change to the speed you want in your game/* * delta;
public void walkForward() {
position.x += (float) (Math.cos(pitch) * Math.sin(yaw) * speed);
position.y += (float) (Math.sin(pitch) * speed);
position.z += (float) (Math.cos(pitch) * Math.cos(yaw) * speed);
}
(And make sure your pitch and yaw is in radians and not degrees)