For simple collision detection, should we roll our own code or just use native physics lib?

In our current plan, we will never use more than the collision detection and event bubbling part of the native physics engine, is it worth our time to roll our own code?

I mean it’s not difficult to do a simple check with enterFrame and simple bounding box, but I would like to use build-in collision event for simplicity.

Is there way to turn off the “gravity” part and enable only “event” and “body collision detection” part? Is “gravityScale = 0” good enough?

Please imagine we are building a simple RPG in top-down view, where we only need to detect “player reach the town” and “fire event to update town map”.

If you just want to do bounding box checks (non rotated rects) it’s way faster to do your own checks.

But there are a few things to keep in mind:

  1. Depending on the amount of objects, you should apply spacial hashing. So that you only check for collision if object are relatively near to each other.

  2. Only test objects which may collide. Like in Corona, only test “dynamic” objects collision. Two walls will never collide, so you wont need to check for collision between those.

  3. Apply collision Maks like in Corona, for objects, that will not collide with each other. (bullets for example)

So if your able to make the system efficient, it will be faster as the build in physics.

But if that’s too much work, just use the physics engine, set gravity to zero, set isSensor = true for all bodys and move objects by directly setting there x and y positions (don’t use setLinearVelocity etc.). Use collision masking and dynamic and static objects as mentioned before. If you do so, you can keep the physic engines memory needs to a minimum.

cheers @torbenratzlaff, I will definitely try your suggestions.

If you just want to do bounding box checks (non rotated rects) it’s way faster to do your own checks.

But there are a few things to keep in mind:

  1. Depending on the amount of objects, you should apply spacial hashing. So that you only check for collision if object are relatively near to each other.

  2. Only test objects which may collide. Like in Corona, only test “dynamic” objects collision. Two walls will never collide, so you wont need to check for collision between those.

  3. Apply collision Maks like in Corona, for objects, that will not collide with each other. (bullets for example)

So if your able to make the system efficient, it will be faster as the build in physics.

But if that’s too much work, just use the physics engine, set gravity to zero, set isSensor = true for all bodys and move objects by directly setting there x and y positions (don’t use setLinearVelocity etc.). Use collision masking and dynamic and static objects as mentioned before. If you do so, you can keep the physic engines memory needs to a minimum.

cheers @torbenratzlaff, I will definitely try your suggestions.