Controlling the Accuracy and Efficiency of Collision Detection in 2d Games using Hitboxes
Paul Sajo, R. Gokulapriya, B N Mithun · 2023
Collision detection is a process in game development that involves checking if two or more objects have intersected or collided with each other. It is a fundamental aspect of game mechanics that cannot be overlooked. Games invloves assets/sprites, which tend to be drawn digitally with the help of a computer program. This paper discusses controlling and detecting collisions in games that make use of PNG images as game assets. The conventional way to detect collision in a game is to check if the object is within the bounding box of another object or asset. However, such a method lacks realism and doesn’t work well with much complex shapes as the game might register a hit when another object collides with the transparent part of the object being checked for collision. In order to overcome these limitations, the proposed algorithm divides the entire image into smaller rectangles and stores its coordinates in an array. The array is then pruned by removing coordinates with no translucent or opaque elements. Collision is detected by checking if any of the points of the collision object is inside the image array.