this is the current set up: ``` const sphereRadius = 50; // Radius of the sphere
if (character) {
const sphereCenter = new THREE.Vector3(0, sphereCenterY, 0);
// Update local axes based on character's position
localUp.copy(character.position).sub(sphereCenter).normalize();
localRight.crossVectors(localForward, localUp).normalize();
localForward.crossVectors(localUp, localRight).normalize();
mouse.movementX = 0;
// Compute the position of the character on the sphere's surface
let fv2 = new THREE.Vector3(0, 0, -1);
fv2.crossVectors(localUp, localRight).normalize();
// Calculate the forward vector (desired horizontal rotation)
let forwardVector = new THREE.Vector3(0, 0, 1); // Adjust this as needed // problem area
// Calculate the quaternion to rotate the character's forward direction to the desired forward vector
let horizontalRotation = new THREE.Quaternion().setFromUnitVectors(fv2, forwardVector);
// Set the character's orientation directly
character.quaternion.copy(horizontalRotation);
// Calculate the new position based on the orientation
let velocityDirection = new THREE.Vector3(0, 0, 0);
if (keys.w) {
velocityDirection.add(localForward);
}
if (keys.s) {
velocityDirection.sub(localForward);
}
if (keys.a) {
velocityDirection.add(localRight);
}
if (keys.d) {
velocityDirection.sub(localRight);
}
velocityDirection.normalize();
// Apply character speed and update position directly
velocityDirection.multiplyScalar(characterSpeed);
character.position.add(velocityDirection);
// Make sure the character stays on the sphere's surface
character.position.sub(sphereCenter).normalize().multiplyScalar(sphereRadius).add(sphereCenter);
character.forwardVector = localForward;```