| Zombie simulator: properly collapsing buildings |
|
| Friday, 22 January 2010 20:27 |
|
OK, I got the bugs worked out of it, buildings are now collapsing a lot more realistically. Dim lights Embed Embed this video on your site The solution turned out to be a mix of modifying the "broken" building model so that the parts were less likely to overlap, and adding in a "fudge factor" to the bounding box calculations, so that if any parts overlapped, the bounding boxes for the parts involved were reduced by about 9%, making the overlap much smaller and the corresponding reaction from the physics engine much weaker. In regards to the bounding box calculations, one of the things I did to improve accuracy was to work out the angle that a collapsing piece started at. This was particularly important with the arched roof on the factory as the way it worked previously, the bounding box included a lot of space created by the roof angle. To get around this, I simply worked out which was the largest triangle in a mesh, then if the normal did not contain a 1 in either the X, Y or Z coordinate, then the piece was assumed to not be aligned along an axis, so I would then just work out the angle of the piece, save the value and "unrotated" it to flatten it. The angle was then used when initialising the physics object so that it started off rotated in such a way as to put the flattened roof piece back where it started. The end result is that the angled roof pieces can now land flat on the ground. Overall, the multi-story building collapses far more realistically, mainly because there are more parts hitting one another on the way down. Here's a shot of what happens to the factory when it starts to "collapse".
The white polygons are actually the physics objects rendered as boxes so that they are visible over the top of the object they represent. As you can see, the boxes for the angled roof pieces are aligned correctly, while many of the roof tiles have had their bounding box reduced so as not to trigger such an extreme reaction from the overlapping pieces. You might also spot where I've simplified the objects slightly, for example, by removing the guttering from the edge of the roof. This also caused the pieces not to fit quite as well, but since the building is falling apart anyway, who cares? The only remaining glitch is that the central roof piece is not at the right height. Since there are no vertices in the space below the roof piece, it's being mis-aligned to the base of just the roof mesh. Not a big deal though since it's only really visible in this static shot and for this particular type of roof. The flat office building roof doesn't suffer from this problem. blog comments powered by Disqus |

