Avoid O(n^2) complexity for collision detection

后端 未结 3 1039
迷失自我
迷失自我 2020-12-29 13:42

I am developing a simple tile-based 2D game. I have a level, populated with objects that can interact with the tiles and with each other. Checking collision with the tilemap

3条回答
  •  萌比男神i
    2020-12-29 14:16

    You can use quadtree to divide the space and reduce the number of objects you need to check for collision.

    See this article - Quadtree demonstration.

    And perhaps this - Collision Detection in Two Dimensions.

    Or this - Quadtree (source included)

    It may seem - at first glance - that it takes a lot of CPU power to maintain the tree, but it also reduces the number of checks significantly (see the demonstration in th first link).

提交回复
热议问题