hex-world
    Preparing search index...

    Class RtsCameraController

    Index

    Constructors

    Accessors

    • get targetPosition(): Readonly<THREE.Vector3>

      The ground point the camera looks at (y = 0). Read-only — do not mutate; use snapTo/panTo.

      Returns Readonly<THREE.Vector3>

    Methods

    • Instantly reposition the camera to look at the given world-space XZ position with no animation. Use at startup or after teleporting so the first frame renders at the correct location rather than sliding in from somewhere else.

      Parameters

      • x: number
      • z: number

      Returns void

    • Smoothly pan the camera to look at the given world-space XZ position. The camera will glide there over the next several frames using the existing damping. Call each frame to track a moving target.

      Parameters

      • x: number
      • z: number

      Returns void

    • Smoothly swing the camera around its target to a compass heading in degrees (0 looks toward −Z). Takes the short way round, so turning from 170° to −170° is a 20° swing rather than a 340° one.

      Parameters

      • degrees: number

      Returns void

      // Face the sunrise, wherever the day/night cycle has put it.
      const s = world.dayNight.evaluate();
      controls.rotateTo(Math.atan2(-s.sunDir.x, -s.sunDir.z) * 180 / Math.PI);
    • Swing the camera by a relative number of degrees (positive = leftward).

      Parameters

      • degrees: number

      Returns void

    • Smoothly tilt to a pitch in degrees above the horizon, clamped to the controller's limits — pass minPitchDeg for the shallowest view the camera allows, which is the one that puts the horizon on screen.

      Parameters

      • degrees: number

      Returns void

    • Re-set how far the camera may tilt, in degrees above the horizon. The current tilt is pulled inside the new range rather than snapped, so tightening the limits glides the view back instead of cutting to it.

      This plus RtsCameraController.setYawEnabled is what a camera-mode switch is made of — the controller supplies the mechanism and leaves the choice of presets to the app, since "how much freedom is too much" is a question about your game, not about the camera.

      Parameters

      • minDegrees: number
      • maxDegrees: number

      Returns void

      // Classic locked-heading RTS view...
      controls.setPitchLimits(30, 66);
      controls.setYawEnabled(false);
      // ...or free look, low enough to see the horizon.
      controls.setPitchLimits(6, 80);
      controls.setYawEnabled(true);
    • Allow or forbid turning the camera around its target. Locking it swings the heading back to restDegrees (0 — the +Z placement the camera has always had) and makes the drag gesture, rotateTo, and rotateBy no-ops until it is unlocked, so a fixed-heading mode can't be nudged out of alignment.

      Parameters

      • enabled: boolean
      • restDegrees: number = 0

      Returns void