Sign in to follow this  

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

Share this post

Link to post
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 



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.