Physics: registering collisions... suggestion

0 favourites
  • 1 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Heyo,

    As I understand it, when using the box2d physics behavior, if two objects begin touching each other, the behavior lets the run time know that a collision has occurred. This means that the relevant trigger will fire, causing all oncollision events to run. Without this, it is possible that objects would never be seen by the runtime as colliding because physics would resolve those collisions before you get to ask if they exist.

    Here is the relevant code:

    // For registering collisions

    var listener = new Box2D.JSContactListener();

    listener.BeginContact = function (contactPtr) {

    var contact = Box2D.wrapPointer(contactPtr, Box2D.b2Contact);

    var behA = contact.GetFixtureA().GetBody().c2userdata;

    var behB = contact.GetFixtureB().GetBody().c2userdata;

    runtime.registerCollision(behA.inst, behB.inst);


    listener.EndContact = function () {}; // unused

    But what is missing here is something to let the runtime know if objects are still touching or InTouch. You can't reliably use isOverlapping events with physics without creating extra sensor objects that are slightly larger (since physics resolves most overlaps before you can aks if something is overlapping)

    This can be changed easily. If the runtime is not capable of this, then a condition and expression could be added to the beahvior which could test if contacts were still IsTouching() via their contacts. Either way it would get the job done. This could also be fixed if the runtime had a OnCollisionEnd trigger.

    Simply creating a physics box that lights up when touching other boxes requires compound objects at the moment, which is somewhat wasteful.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)