Skip to main content
GameDev.net gamedev.net
🔒 Locked

box2d concave interior question

Started by Monkan May 20, 2012 at 10:32 PM 1 replies 1.1k views
Original Post
Monkan
Monkan
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?

Thanks for your help.
"To know the road ahead, ask those coming back."
VildNinja
VildNinja
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
Monkan
Monkan

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 smile.png


Thank you, yeah I've got it now, I had missed the centroid value of the PolygonShape. All sorted now..
"To know the road ahead, ask those coming back."

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.