Sign in to follow this  
caymanbruce

How to build a circular wall in Box2D?

Recommended Posts

Hi I want to make a circular wall/fence in Box2D so all my sprites will be inside this circular wall and they can collide with each other or collide with the wall. How to make a wall like this in Box2D? Or is it better that if I just implement my own collision detection with the circular wall?

I know how to draw an edge as a fence in Box2D but that fence is always straight and open. If I were to draw a circular wall it would look like a body in Box2D I don't know if other bodies can move and collide inside a body like that.

Share this post


Link to post
Share on other sites
Last time I did something similar a few years ago, I just constructed the "circle" from lots of boxes, arranged in a circle so that the inner shape was like a many-sided polyhedron.

That was more than accurate enough and combined with a graphical circle, gave the correct impression.

Share this post


Link to post
Share on other sites

Last time I did something similar a few years ago, I just constructed the "circle" from lots of boxes, arranged in a circle so that the inner shape was like a many-sided polyhedron.

That was more than accurate enough and combined with a graphical circle, gave the correct impression.

 

Thanks that sounds like a good idea. How does the performance go? I mean when we need to do collision detection with that chained boxes, there would be a lot more calculation than simple geometric calculation like checking if the sprites go beyond the radius.

Share this post


Link to post
Share on other sites

Hi, my box2d is also very rusty, but you shouldn't need boxes if you only need the collisions to be against an edge.
The question here is if the boxes (Non-AABB) will perform better than the polygon shapes.

There's this website I used a lot, years ago, when learning box2d: http://www.iforce2d.net/b2dtut/fixtures
I sent the link about fixtures, there you can read about PolygonShape; that's why I'd try first. Make sure to check the limit of vertices on the polygon shape.

Also, about the circle, the idea sounds great, but I never saw anything like an empty circle shape on box2d, so I don't think you can get away with something that simple (even you should be able to, in theory).

Cheers

Share this post


Link to post
Share on other sites

Last time I did something similar a few years ago, I just constructed the "circle" from lots of boxes, arranged in a circle so that the inner shape was like a many-sided polyhedron.

That was more than accurate enough and combined with a graphical circle, gave the correct impression.

 
Thanks that sounds like a good idea. How does the performance go? I mean when we need to do collision detection with that chained boxes, there would be a lot more calculation than simple geometric calculation like checking if the sprites go beyond the radius.


The game I was working on created huge levels with hundreds of Box2D shapes and I never had any performance issues. This was years ago on far less powerful machines than we have today.

Box2D has a highly optimised broadphase so you almost certainly don't need to worry about this.

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