Jump to content

1 sprite 2 bodies (Hiboxes)


Recommended Posts

Hey guys, i'm trying to implement hitboxes with p2 physics.

I all ready have a solution, but i find it kind of awkward.


What i want to do is create a sprite, and attach multiple p2 bodies to it,

the main body is the players hitbox which is just a normal polygon body.

the other bodies are all set up as sensors so the don't mess with physics but still trigger the collide.

I tried adding multiple sprites as childs with their own bodies, but that wont work.


Has anyone done this before, or do i have to digg in deep?




ps: my current solution is creating sprites that are not linked together in any way, and than moving them all to the players position. laggy as hell

Link to comment
Share on other sites

found a solution :)


player being the player sprite

hitbox being the hitbox sprite

hitbox.body.mass 0.00001;
game.physics.p2.createLockConstraint(, hitbox, [0, 0], 0, 9999);


i have some stuff set by default to all objects, so you might have to fiddle a bit to get it work.

but this is way more fluid then the tracking method 



Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...