1 Reply Latest reply: Mar 3, 2012 3:38 PM by Ninarama RSS

    Physics Engine: How to handle object collisions / best practices?

    Ninarama Community Member

      Right now I'm trying to find out by examining all methods and comparing to other engines like box2D how to get information about colliding objects.

       

      I thought I could use i.E. the "checkCollideWith" method of the btRigidBody instance, but it always returns true.

      Then, there are several interesting methods in the collisionDispatcher class, but also they don't yield any satisfying results.

      I could set a "nearCallbackFunction", but then, the collision wasn't handeled internally anymore.

       

      Has anyone found out how to get reliable information about colliding objects?

       

      Also the Pellet-Engine looks really "ported from C++", not like a typical AS3 project. I could imagine that Adobe would refactor the whole thing at a given time to make it fit more into their AS3 environment. Then, there would also be "real" events for things like that.

        • 1. Re: Physics Engine: How to handle object collisions / best practices?
          Ninarama Community Member

          Well I answered it myself. I should have noticed that "Pellet" sounds familiar. Like the physics engine used in Blender3D, "Bullet".

          And when I looked at the wiki, I found out that Pellet was a clone of Bullet so I could easily port these lines of code to AS3:

          // inside onAnimate method of BasicScene
          
                         var numManifolds:int = _dynamicsWorld.getDispatcher().getNumManifolds();
                         for (i = 0; i < numManifolds; i++) {
                              var contactManifold:btPersistentManifold = _dynamicsWorld.getDispatcher().getManifoldByIndexInternal(i);
                              var obA:btCollisionObject = contactManifold.getBody0();
                              var obB:btCollisionObject = contactManifold.getBody1();
                              var numContacts:int = contactManifold.getNumContacts();
                              var j:int;
                              for (j = 0; j < numContacts; j++) {
                                   var pt:btManifoldPoint = contactManifold.getContactPoint(j);
                                   if (pt.getDistance() < 0) {
                                        // const btVector3& ptA = pt.getPositionWorldOnA();
                                        // const btVector3& ptB = pt.getPositionWorldOnB();
                                        // const btVector3& normalOnB = pt.m_normalWorldOnB;
                                        trace ("yay, dingdingding! => " + obA + ", " + obB+ " collided!");
                                   }
                              }
                         }
          

          I just used the code described here:

          http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers

           

          You can get the full documentation here:

          http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Documentation

           

          Probably everything will also work in Pellet this way, you've just port the code to AS3, no need to even change variable or method names, it seems to be all the same in Pellet.