How to build a circular wall in Box2D?

Started by
3 comments, last by Aardvajk 6 years, 12 months ago

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.

Advertisement
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.

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.

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

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.

This topic is closed to new replies.

Advertisement