In my opinion, if you're using MoveLoc and trying to do the math yourself, you're not using the physics library. What you should be doing is simply initializing the properties of the characters in your game with the proper physics constraints - dynamics, type, friction, density, etc. and then just letting the physics simulation run its course, updating the characters of your game according to such definitions.
With regards to using box2d, you then have the bonus of being able to use its collision-detection system and get it such that you really can do:
- Code: Select all
-- handle collisions between items
function handle_character_collision(event, fixtureA, fixtureB, arbiter)
-- two items have touched each other
if event == MOAIBox2DArbiter.BEGIN then
if fixtureA.userdata and fixtureB.userdata then
if fixtureA.name and fixtureB.name then
print(" fixtureA " .. fixtureA.name .. " fixtureB " .. fixtureB.name)
end
print( fixtureA.userdata.." collided with " .. fixtureB.userdata)
-- &etc.
with the setup code, of course being done on Fixture creation with masks:
- Code: Select all
-- init of game characters ..
character_bodies[1]:resetMassData()
character_fixtures[1]:setCollisionHandler(handle_character_collision, MOAIBox2DArbiter.BEGIN + MOAIBox2DArbiter.END, PLAYER_CATEGORY)
character_bodies[2]:resetMassData()
character_fixtures[2]:setCollisionHandler(handle_character_collision, MOAIBox2DArbiter.BEGIN + MOAIBox2DArbiter.END, WALL_CATEGORY)
character_bodies[3]:resetMassData()
character_fixtures[3]:setCollisionHandler(handle_character_collision, MOAIBox2DArbiter.BEGIN + MOAIBox2DArbiter.END, BADDY_CATEGORY)
.. and so on (see docs for setCollisionHandler masks.. its a simple mask op) ..