update method

void update(
  1. double dt
)

Applies WASD locomotion for frame time dt (seconds). Movement is relative to the camera's yaw (ground-plane projection). Called automatically by VREngine each tick when enabled.

Implementation

void update(double dt) {
  if (!enabled || _pressedKeys.isEmpty) return;

  var ix = 0.0;
  var iz = 0.0;
  var iy = 0.0;
  if (_pressedKeys.contains(keyForward)) iz += 1;
  if (_pressedKeys.contains(keyBackward)) iz -= 1;
  if (_pressedKeys.contains(keyRight)) ix += 1;
  if (_pressedKeys.contains(keyLeft)) ix -= 1;
  if (_pressedKeys.contains(keyUp)) iy += 1;
  if (_pressedKeys.contains(keyDown)) iy -= 1;
  if (ix == 0 && iz == 0 && iy == 0) return;

  final sprinting = _pressedKeys.any(_isSprintKey);
  final speed = moveSpeed * (sprinting ? sprintMultiplier : 1.0);

  // Ground-plane forward/right from camera yaw
  final fwd = cameraRig.headTransform.forward.clone()..y = 0;
  if (fwd.length2 < 1e-8) {
    fwd.setValues(0, 0, -1); // Looking straight up/down: use default forward
  } else {
    fwd.normalize();
  }
  final right = fwd.cross(Vector3(0, 1, 0))..normalize();

  final move = (fwd * iz + right * ix + Vector3(0, iy, 0));
  if (move.length2 > 1.0) move.normalize();

  cameraRig.position += move * speed * dt;
}