Smooth camera rotation

my camera rotation is choppy, how can i make it smooth

const [rotationX, setRotationX] = useState(0);

  const [rotationY, setRotationY] = useState(0);

  const handleKeyDown = (event: KeyboardEvent) => {

    if (cameraRef !== null && cameraRef.current !== null) {
    
    console.log((cameraRef.current as UniversalCamera).rotation);
    
    }
    
    if (event.key == "d" || event.key == "D") {
    
    setRotationY((rotationY) => rotationY + 0.01);
    
    }
    
    if (event.key == "a" || event.key == "A") {
    
    setRotationY((rotationY) => rotationY - 0.01);
    
    }
    
    if (event.key == "w" || event.key == "W") {
    
      setRotationX((rotationX) => rotationX + 0.2);
    
    }
    
    if (event.key == "S" || event.key == "s") {
    
      setRotationX((rotationX) => rotationX - 0.2);
    
    }
    
    };

  useEffect(() => {

    window.addEventListener("keydown", handleKeyDown);
    
    return () => {
    
    window.removeEventListener("keydown", handleKeyDown);
    
    };
    
    }, []);

  return (
    <>
      <universalCamera
        name="universal"
        target={new Vector3(0, 0, 0)}
        position={new Vector3(0, 0, 0)}
        rotation={new Vector3(rotationX, rotationY, 0)}
        speed={1}
        angularSensibility={1800}
        fov={1}
        touchAngularSensibility={1000}
        touchMoveSensibility={0}
        ref={cameraRef}
      />

Hi,
You can ease the camera using the easing function and (although I never tried it) it looks like you can even use bezier curves.

2 Likes

Hello @cosmos just checking in if you’d like any more help with this.

Used this