Amon
Member
- Joined
- Nov 19, 2018
- Location
- Shropshire, United Kingdom
How would I go about making Circle to Circle collisions in CX?
'-----------------------------------------------------------------------------
Function Coll_Circle2Circle:Bool(x1:Float, y1:Float, radius1:float, x2:Float, y2:Float, radius2:float)
Local xf:Float
Local yf:Float
Local rf:Float
xf = x1 - x2
xf *= xf
yf = y1 - y2
yf *= yf
rf = radius1 + radius2
rf *= rf
If (xf+yf) < rf Then Return True
Return False
End
Circle-circle is easy: just get the distance between the center of both circles (using Pythagora's Theorem) and see if it's equal or smaller then the sum of the radius (radi?) of both spheres.
Once you know/understand that, you can write that function above with your eyes closed
I know, it's a common optimization for that - the other one being xdiff = x2-x1; xdiff*=xdiff to avoid pow(2)You don't need to take the square root