Physics: registering collisions... suggestion

Discussion and feedback on Construct 2

Post » Fri Feb 20, 2015 9:20 pm

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.
Image
B
31
S
11
G
2
Posts: 555
Reputation: 5,055

Return to Construct 2 General

Who is online

Users browsing this forum: andreyin, Lof and 7 guests