Tuesday, May 14, 2024
HomeGame Developmentjavascript - Object collision detection and resolution with complex polygons

javascript – Object collision detection and resolution with complex polygons


I am having trouble coding collision detection between a single point projectile and numerous irregular polygons. The steps I have taken:

  1. Used a ray casting algorithm to determine if the projectile will be inside a polygon in the next instance
  2. Find the closest intersection between the projectile’s vector and all lines in the polygons. This helps to:
  3. Find the closest line in the projectiles path.
  4. Run the vector reflection formula with the slope of the line, and resolve the collision

Though I seem to have some problem I can’t solve, the projectile takes a different path depending on its velocity, which it shouldn’t as there is no gravity or friction. It also tends to glitch through certain shapes depending on its velocity.

Code here:
https://github.com/Beluker/Collision
sorry its messy

any help at all is appreciated : D

the projectile is in an array accessible through the console.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments