Sunday, December 2, 2012

Adding collision to entities

As demonstrated in an earlier post, the level editor allows me to edit the collision model of a tile independent of the actual graphic. Before I jumped into scripting, I realized it may be wise to go ahead and implement the same logic for entities (entities are freely positioned, scaled, and rotated objects). This was fairly simple, since the collision detection algorithm was coded to operate on arbitrary polygon models, not just axis-aligned tiles.

Video! Here's some footage of me actually using the editor to show how I set these things up. I create some entities, transform them a bit, set some different collision models on them, and then demonstrate the results in-game.

The prototypes for collision models (you can see them in the video as 'solid', 'half triangle', etc.) are defined as polygons in the unit square space (x and y coordinates between -.5 and .5). I thought it might be neat to show how easy it is for me to add more of them, from start to finish, including the programming. The only thing I've done ahead of time is make the editor graphical representation of the model, which you can see me copying into the texture atlas at the beginning of the video. This one's probably better in highest quality since the code blurry otherwise.

No comments:

Post a Comment