a327ex / windfield

Physics module for LÖVE
453 stars 55 forks source link

Using normal body+fixture+shape #11

Closed taxilly closed 6 years ago

taxilly commented 6 years ago

A collider is a composition of a single body, fixture and shape. For most use cases whenever box2d is needed a body will only have one fixture/shape attached to it, so it makes sense to work primarily on that level of abstraction.

Is kind of limiting if I want to make bodies with multiple fixtures - connecting bodies together via WeldJoints is not a solution as they are not rigid.

My question is is how (if even possible) can I use a typical body+shape+fixture setup inside windfield, whilst still retaining all the collision classes stuff - scouring the source a little bit showed me that the box2d world is contained within box2d_world, so my first attempt was;

  export world = wf.newWorld(0, 0, true)
  body = love.physics.newBody( world.box2d_world, 10, 10, "static" )

Which yields the error init.lua: 185: attempt to index a nil value in function collisionEventsClear

a327ex commented 6 years ago

Sorry it took long to answer to this, for some reason issue creations are not showing up on my feed. You can use the addShape and removeShape functions to add/remove shape+fixture pairs to an existing body. The added shape/fixture pairs can be accessed via their name at collider.shapes_list[name] and collider.fixtures_list[name]. They're all attached to the same body under the collider, which can be accessed at collider.body.