Comments on: Simple platformer game in XNA tutorial – part four “Simple collision detection” http://xnafan.net/2013/04/simple-platformer-game-in-xna-tutorial-part-four-simple-collision-detection/ XNA tutorials, code and games Fri, 10 Aug 2018 04:55:21 +0000 hourly 1 https://wordpress.org/?v=4.2.22 By: Steven Vaerten http://xnafan.net/2013/04/simple-platformer-game-in-xna-tutorial-part-four-simple-collision-detection/comment-page-1/#comment-398038 Fri, 10 Aug 2018 04:55:21 +0000 http://xnafan.net/?p=977#comment-398038 See: "2D Collision Detection for Game Programmers: Focus on Circle Collisions" on Amazon.com for a detailed answer to this question.

This question is not easily answered. There are 3 types of collision algorithms that may be written: Static, Semi-Dynamic, and Dynamic. Most of the discussions here were for Static collisions. Static collisions are when the algorithm assumes that the two objects are static, or not moving, even it they are actually moving. Semi-Dynamic collision algorithms account for object A moving, but assumes object B is static. Dynamic collision algorithms take into account that both objects are moving.

Static collision algorithms return only if a collision has occurred. The programmer only has the location of the objects to use for collision response. This is limiting, but sufficient for many games. Games like "Space Invaders" may be written using the algorithm. It is important to note that the static algorithms can have issues with small fast moving objects. Care must be taken to insure these objects cannot skip over each other in a single frame.

Semi-Dynamic collision algorithms return if a collision has occurred, The mathematical intersection point, the intersection time, the collision point (Where the two objects touch), and the collision normal. These algorithms take more time to execute, but return more information to allow for a wide variety of collision responses. This is the recommended algorithm I would use for most games. Games like "Break Out" may be written using this algorithm.

Dynamic collision algorithms return if a collision has occurred, the mathematical intersection point, the point where object A is at collision, the point where object B is at collision, the collision point, the collision normal for object A, and the collision normal for object B. This algorithm is the slowest to execute, but gives all the collision response details possible. This algorithm would be suitable to a "Break Out" like game that has multiple ball and if the balls collide they bounce off each other. Typically "Break Out" like game do not have the balls interacting with each other, therefore, the balls can occupy the same location with no response. This is not realistic, but how it is usually done.

The process for building the algorithms is fairly simple, but filled with a lot of repeating detail that make it cumbersome. The algorithms can be broken down into the following steps:

1) Identify the 2 objects to test for a collision
2) Create the collision area.
3) Test if the control point collides with any of the objects that make up the collision area. Divide and conquer decisions should be used to maximize efficiency.

The collision area is a composite of the 2 objects colliding. To create the collision object take object A and transcribe object A around object B. In the case of a circle colliding with an AABB, the collision area will have 4 circles at its corners, and 4 segments connecting the circles at their outer tangent points.

There is insufficient space in this blog give the algorithms in detail, but in the book "2D Collision Detection Algorithms for Game Programmers: Focus on Circle Collisions" will explain all 3 collision types for circles colliding with Points, Lines, Horizontal Lines, Vertical Lines, Rays, Segments, Circles, Ellipses, Axis Aligned Bounding Boxes (AABB), Object Oriented Bounding Boxes (OOBB), Capsules, and Polygons. I highly recommend this book.

You may also be interested in my other books also, they may be found at Amazon.com:

1) "2D Collision Detection for Game Programmers: Focus on Point Collisions"
2) "2D Collision Detection for Game Programmers: Focus on Circle Collisions"
3) "2D Collision Detection for Game Programmers: Focus on Ellipse Collisions"

In print soon:
4) "2D Collision Detection for Game Programmers: Focus on Axis Aligned Bounding Box (AABB) Collisions"
5) "2D Collision Detection for Game Programmers: Focus on Object Oriented Bounding Box (OOBB) Collisions"
6) "2D Collision Detection for Game Programmers: Focus on Capsule Collisions"
7) "2D Collision Detection for Game Programmers: Focus on Polygon Collisions"
8) "2D Collision Detection for Game Programmers: Focus on Collision Response"

Good luck with your game.

]]>