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);
}