1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
moveBall(){
let moveX = moveDirection.left - moveDirection.right;
let moveZ = moveDirection.forward - moveDirection.back;
if( moveX == 0 && moveZ == 0) return;
// apply camera rotation
const camera = getCamera()
const Yaxis = new THREE.Vector3(0,1,0)
const Zaxis = new THREE.Vector3().copy( this.ball.position ).sub( camera.position ).normalize();
const Xaxis = new THREE.Vector3().copy(Zaxis).applyAxisAngle(Yaxis, Math.PI/2)
const acceleration = new THREE.Vector3().addScaledVector(Zaxis, moveZ).addScaledVector(Xaxis, moveX)
let resultantImpulse = new Ammo.btVector3( acceleration.x, 0, acceleration.z)
resultantImpulse.op_mul(CONTROL_FORCE);
let physicsBody = this.ball.userData.body;
physicsBody.applyForce( resultantImpulse );
} |