Birch-san / box2d-wasm

Box2D physics engine compiled to WebAssembly. Supports TypeScript and ES modules.
263 stars 21 forks source link

How to realize collision detection #48

Closed a6965921 closed 2 years ago

a6965921 commented 2 years ago

How to realize collision detection

Similar box2dweb image

a6965921 commented 2 years ago

const { b2_dynamicBody, b2BodyDef, b2CircleShape, b2Color, b2Draw: { e_shapeBit }, b2EdgeShape, b2Transform, b2Vec2, b2PolygonShape, b2World, JSDraw, wrapPointer, JSContactListener, b2Contact } = box2D;

var listener = new JSContactListener(); listener.BeginContact = function (contactPtr) {

  var contact = wrapPointer(contactPtr, b2Contact);
  var bodyAY = contact.GetFixtureA().GetBody().GetPosition().get_y();
  var bodyBY = contact.GetFixtureB().GetBody().GetPosition().get_y();
  console.log("bodyAY",bodyAY);
  console.log("bodyBY",bodyBY);

}

use it can resolve it