Oval collision detection not working properly

后端 未结 4 1981
逝去的感伤
逝去的感伤 2021-01-24 01:54

So I\'m trying to implement a test where a oval can connect with a circle, but it\'s not working.

edist = (float) Math.sqrt(
    Math.pow((px + ((pwidth/2) )) -          


        
4条回答
  •  悲&欢浪女
    2021-01-24 02:25

    Is using ovals an absolute requirement? You can approximate collisions between fancier shapes by representing them with multiple circles. That way you can use very a simple collision detection between circles and still achieve a high level of accuracy for the viewer.

    collision(c1, c2) {
      dx = c1.x - c2.x;
      dy = c1.y - c2.y;
      dist = c1.radius + c2.radius;
    
      return (dx * dx + dy * dy <= dist * dist)
    }
    


    (source: strd6.com)

提交回复
热议问题