Skip to content

Instantly share code, notes, and snippets.

@BlueMagnificent
Created August 2, 2020 22:55
Show Gist options
  • Save BlueMagnificent/e507c8e30e62b3000e123f4bf6636633 to your computer and use it in GitHub Desktop.
Save BlueMagnificent/e507c8e30e62b3000e123f4bf6636633 to your computer and use it in GitHub Desktop.
Javascript 3D Physics Tut 3 Update Physics
function updatePhysics( deltaTime ){
// Step world
physicsWorld.stepSimulation( deltaTime, 10 );
// Update rigid bodies
for ( let i = 0; i < rigidBodies.length; i++ ) {
let objThree = rigidBodies[ i ];
let objAmmo = objThree.userData.physicsBody;
let ms = objAmmo.getMotionState();
if ( ms ) {
ms.getWorldTransform( tmpTrans );
let p = tmpTrans.getOrigin();
let q = tmpTrans.getRotation();
objThree.position.set( p.x(), p.y(), p.z() );
objThree.quaternion.set( q.x(), q.y(), q.z(), q.w() );
}
}
detectCollision();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment