updated_at: 2025-04-30 20:39

requestAnimationFrame

private clock = new THREE.Clock();

public render() {
  const delta = this.clock.getDelta();
  const elapsedTime = this.clock.getElapsedTime();

  this.renderer.render( this.scene, this.camera );
}

 public update = () => {
  this.render();
  requestAnimationFrame(this.update);
}

이동

간단한 예제

키보드 코드를 입력 받아서 처리, 이때 thrustImpulse 가 기본 값이 된다.

// this.player: RAPIER.RigidBody

public render() {
  const thrustImpulse = 0.1;
  switch (keyboardEvent.code) {
    case 'ArrowUp':
      forceVector = new THREE.Vector3(0, 0, -thrustImpulse).applyMatrix4(new THREE.Matrix4());
      // this.player.applyEngineForce(up ? 0 : -maxForce, 2);
      break;
    ..........
  }

  this.player.applyImpulse(forceVector, true);
}

속도 조절 예제

평점을 남겨주세요
평점 : 2.5
총 투표수 : 1

질문 및 답글