 
                 for j in [0...manifoldArray.size()]
                     manifold = manifoldArray.at(j)
-                    isFirstBody = manifold.getBody0().ptr == p
+                    b0 = manifold.getBody0().ptr
+                    b1 = manifold.getBody1().ptr
+                    isFirstBody = b0 == p
                     for j in [0...manifold.getNumContacts()]
                         point = manifold.getContactPoint(j)
                         if point.getDistance() < margin


    make_ghost: ->
        @is_ghost = true
        @btbody?.setCollisionFlags(@btbody.getCollisionFlags() | 4)

    clear_ghost: ->
        @is_ghost = false
        @btbody?.setCollisionFlags(@btbody.getCollisionFlags() & -5)

    update_transform: ->

            @btworld.addRigidBody(@btbody, @group, @mask)
        if @no_sleeping
            @disallow_sleeping()
        if @is_ghost or @type == 'SENSOR'
            @make_ghost()
        @update_transform()
        @world.pointer_to_body[@btbody.ptr] = this

    get_physics_mesh: (use_visual_mesh=@_use_visual_mesh) ->
        if @type == 'NO_COLLISION' or
