Collision detection : rounded object

后端 未结 4 1871
再見小時候
再見小時候 2021-01-15 11:08

I\'m developing a Java game (but the dev. language doesn\'t really matter) including rounded objects like balls or pucks, and now working on collisions. I use a timer, so o

4条回答
  •  生来不讨喜
    2021-01-15 11:52

    An addition to @Ankit's solution:

    boolean areColliding(Circle c1, Circle c2){
    
        center_distance = (x1-x2)^2 +(y1-y2)^2;  //this is the distance between the centers of the two circles.
    
        if((c1.r+c2.r)^2 < center_distance)
            return false;
        else
            return true;
    }
    

    This just compares the squared distances. Result is the same, but no square root and huge performance benefit.

提交回复
热议问题