Collision Detection of Sprites in Actionscript 3.0 Flash

后端 未结 3 1596
我寻月下人不归
我寻月下人不归 2021-01-16 11:28

I am making an achtung die kurve-like game in AS3.0. So far I\'ve done the movements of the 4 different players, and it works alright.

I am now to make collision de

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 11:53

    Looking at the screenshots of that game, I think the best model would be to describe each worm as a chain of circles. Then divide the world/level in a grid with cells somewhat larger than the circle radii.

    The collision check would then be:

    1. clear grid
    2. place each circle into the 1 or more grid cells it falls in
    3. iterate over all cells, for each cell:
      • for each pair of circles (partially) in this cell, check if they intersect. If they do; collision. Note that this may result in more than 1 collision occurrence between circle A and B, so you'd also need to check that to avoid duplicates.

    Step 1 and 2 can be optimized by not clearing the grid, and instead of step 2, updating each circle's cell after it moves. If you size your cells like 5x the size of a circle, a circle can stay in the same cell for a few frames, avoiding excessive add/remove operations.

    I'm doing something similar in a project of mine right now, except with space ships! My grid cells are currently 256x256 (too big for your project I think) and my units have radii of about 20.

提交回复
热议问题