• Create Account

# box2d concave interior question

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Monkan  Members   -  Reputation: 256

Like
0Likes
Like

Posted 20 May 2012 - 04:32 PM

Hi,

I'm using Box2d.
In my game I have buildings that you can enter and when you are inside I want you not to be able to walk outside of the edges of the building. When I say building I basically mean rectangle.

At first I was wondering if there was a way to set a box2d body to stop other bodies leaving it instead of separating them (basically the opposite) but I don't think you can do this.

Then I thought I would make 3 separate bodies each with a different shape which would be the 2 walls and the ceiling and then I would connect them with a couple of joints. This method seems a bit overkill in my mind.

What I would like ideally is 1 body with 3 shapes attached to it so the centre of the body is still the centre of the building but I can't think of a way to do this as I'm not too sure how I would position the shapes.

Have I missed something really obvious?

Does anyone know a good way of doing this?

### #2VildNinja  Members   -  Reputation: 325

Like
1Likes
Like

Posted 20 May 2012 - 05:06 PM

You can add multiple fixtures to a body. You should add three. For each fixture you should add a box shape and position the shape relative to the center i.e. (0,1) for roof, (1,0) for wall, and (0,-1) for floor.

Hope this helps

### #3Monkan  Members   -  Reputation: 256

Like
0Likes
Like

Posted 21 May 2012 - 12:31 AM

You can add multiple fixtures to a body. You should add three. For each fixture you should add a box shape and position the shape relative to the center i.e. (0,1) for roof, (1,0) for wall, and (0,-1) for floor.

Hope this helps

Thank you, yeah I've got it now, I had missed the centroid value of the PolygonShape. All sorted now..