Currently, I am working on an FPS game where the player controller applies force based on keyboard inputs to a dynamic cannon body. The angular dampening is set to 1 on the player body. The PlayerController class takes both the player class (which extends the Cannon Body class) and a THREE.js camera as parameters. The keyboardControls method is called in the animate function of the main script, with the world gravity set to -20.
export class PlayerController {
private player: Player;
private camera: THREE.PerspectiveCamera;
private cameraControls: PointerLockControls;
private keys: { [key: string]: boolean } = {};
constructor(player: Player, camera: THREE.PerspectiveCamera) {
this.player = player;
this.camera = camera;
this.cameraControls = new PointerLockControls(this.camera, document.body);
document.addEventListener("click", () => {
this.cameraControls.lock();
document.addEventListener("keydown", (event) => {
this.keys[event.key] = true;
});
document.addEventListener("keyup", (event) => {
this.keys[event.key] = false;
});
});
}
keyboardControls() {
// Code for controlling player movement based on keyboard inputs
}
}
The issue I'm facing is that when keyboard input is provided, the player body moves smoothly along the x, y, and z axes but bounces on the y-axis as it moves along the x and z axes. The ground in the game is just a rotated 90-degree box body. Any assistance in completely removing this bouncing behavior would be highly appreciated.