Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I efficiently simulate a grid of static rectangles in a physics engine?
    text
    copied!<p>I'm making a space shooter which takes place in a big dungeon, which consists of large rectangles to define walls. Everything in the game is physically simulated using Farseer Physics. There's one problem though: I want the dungeon to look sufficiently large, but that requires me to have at least 80x80 rectangles in my grid, which means that I have, in the worst case scenario, 6400 physically simulated bodies, which isn't exactly performance friendly, as you can guess.</p> <p>My temporary solution was to divide the grid in vertical slices, so that, for every column, all rectangles are added using a boolean add operation, and then a body is created, using the resulting concave polygon. It increases performance a bit, but the polygons have a tendency to mess up, become non-existent, block ways that should normally be traversable or even become invalid and cause Farseer to crash.</p> <p>I've been thinking about making some kind of algorithm that somehow finds the biggest areas of walls and merges them together into one big rectangle, and keeps doing this for smaller rectangles until all holes are filled, but I have no idea how to implement this. It seems like the perfect solution because it'd solve the performance problems and also the concave polygon mess I have right now. Does anyone have a clue on how to implement something like this?</p> <p>It is not a solution to stop using a physics engine altogether, because a lot of things in my game rely on it.</p> <p>EDIT: Here's a little example of how the bodies look like right now: (every number is a body) <img src="https://i.stack.imgur.com/c7RRh.png" alt="http://i.imgur.com/6x06o.png"></p> <p>And this is how I want them to be:</p> <p><img src="https://i.stack.imgur.com/zs6De.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload