I’m trying to make a game where I have a ball, and instead of moving the ball I move the platform she’s in, I’m trying to rotate the platform (with WASD), and I got it working, but I’d like to be able to rotate it with the direction of the camera (Being able to only use the W key to rotate in every direction). I still want to be able to use the other keys aswell, to rotate it based on the camera point.
let maxRotationX = Math.PI / 8;
let maxRotationZ = Math.PI / 8;
if (keys["KeyW"] && platformMesh.rotation.x > -maxRotationX) {
platformMesh.rotation.x -= rotationSpeed;
} else if (platformMesh.rotation.x < 0) {
platformMesh.rotation.x += resetSpeed;
}
if (keys["KeyS"] && platformMesh.rotation.x < maxRotationX) {
platformMesh.rotation.x += rotationSpeed;
} else if (platformMesh.rotation.x > 0) {
platformMesh.rotation.x -= resetSpeed;
}
if (keys["KeyA"] && platformMesh.rotation.z < maxRotationZ) {
platformMesh.rotation.z += rotationSpeed;
} else if (platformMesh.rotation.z > 0) {
platformMesh.rotation.z -= resetSpeed;
}
if (keys["KeyD"] && platformMesh.rotation.z > -maxRotationZ) {
platformMesh.rotation.z -= rotationSpeed;
} else if (platformMesh.rotation.z < 0) {
platformMesh.rotation.z += resetSpeed;
}
platformBody.quaternion.setFromEuler(platformMesh.rotation.x, platformMesh.rotation.y, platformMesh.rotation.z);
physicsWorld.step(1 / 60);
sphereMesh.position.copy(sphereBody.position);
This code lives inside of a function that lives inside the animate() function, I’ve tried a lot of different things but I can’t seem to make it work.