Sign in to follow this  

Different shapes in a single body with different collision mask

Recommended Posts

I am trying to make a combat game. I want players to collide with the ground like normal, but to interact differently when they collide with other players. To do this, I've created a body with two shapes, one that is not a sensor, and collides with the ground, and one that is a sensor, and collides with other players.


When I try to have both of the shapes active on the body, however, I fall through the ground. When only the ground colliding shape is active, the ground collision happens, but the other collision (obviously) does not happen.


Is this a limitation in the p2 physics engine that doesn't allow a body to have shapes with different collision masks, or or do you think there is something I am doing wrong to mess this up?


Below is the code I'm using to add the shapes to the body. I set the collision mask when I load the shapes earlier in the code.

for (var i = 0; i < groundCollisionShapes.length; i++) {	this.body.addShape(groundCollisionShapes[i], groundCollisionShapes[i].offset);}for (var i = 0; i < playerCollisionShapes.length; i++) {	this.body.addShape(playerCollisionShapes[i], playerCollisionShapes[i].offset);}

Share this post

Link to post
Share on other sites

I'm totally sure it's possible.


I believe you could try to change the colisions mask after creating all the shapes.

I know I had to do a little trick like that. If you don't find I'll check this in a few hours.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.