I’m currently working on creating hitboxes for characters and enemies that are not the bounding box of the sprite.
I’ve created a group for each character state (idle, attack, etc). In each group there is a sprite that plays the appropriate animation and a roundedRect display object with an attached physics body. The group is then moved to the appropriate position on the screen.
It seems that the collision detection does not take into account the transform of the group and just takes the position of the roundedRect in its local coordinates.
local physRect = display.newRoundedRect( -95, -5, 90, 35, 10 )
physRect:setFillColor( 255, 255, 255 )
physRect.alpha = 0.5
physics.addBody( physRect, "dynamic", { isSensor = true, density = 10.0, friction = 0.5, bounce = 0.2 } )
physRect.isBullet = true
player[i]:insert( 1, physRect )
physics.addBody( player[i][1], "static", { density = 10.0, friction = 0.5, bounce = 0.2 } )
In the above code player[i] is the group.
The enemies’ have dynamic sensor body types and that used to work fine before I restructured things with groups. None of the combinations of body types with and without sensor flag set that I’ve tried seem to work. [import]uid: 6259 topic_id: 1663 reply_id: 301663[/import]