Skip to content

Instantly share code, notes, and snippets.

@BlueMagnificent
Last active August 2, 2020 22:52
Show Gist options
  • Save BlueMagnificent/8f789228ead2d16f487ee794dcc4bc03 to your computer and use it in GitHub Desktop.
Save BlueMagnificent/8f789228ead2d16f487ee794dcc4bc03 to your computer and use it in GitHub Desktop.
Javascript 3D Physics Tut 3 Detect Collision
function detectCollision(){
let dispatcher = physicsWorld.getDispatcher();
let numManifolds = dispatcher.getNumManifolds();
for ( let i = 0; i < numManifolds; i ++ ) {
let contactManifold = dispatcher.getManifoldByIndexInternal( i );
let numContacts = contactManifold.getNumContacts();
for ( let j = 0; j < numContacts; j++ ) {
let contactPoint = contactManifold.getContactPoint( j );
let distance = contactPoint.getDistance();
console.log({manifoldIndex: i, contactIndex: j, distance: distance});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment