Search code examples
javascriptcanvashtml5-canvas

How I can detect collision with any shape in HTML5 canvas?


I am trying to building a HTML5 canvas game so that I will need to detect collision with character with different shape.

If you have enough knowledge about this type of collision please share your knowledge


Solution

  • Depends on personal preference. One of them is Distance Detection.
    Check the distance between two objects(or coords of said object), and if its close enough, count it as hit. You could also check overlap this way, which is a definite hit. Then just apply whatever physics you wanted to apply.