Well, firstly, you forgot to have an else clause :
public boolean checkCircleCollision(float x1, float y1, float r1, float x2, float y2, float r2) { if (Math.sqrt(((x2 - x1) ^ 2) + ((y2 - y1) ^ 2)) <= (r1 + r2)){ return true; } else { return false; } }
Someone else pointed out , this can be shortened as follows:
public boolean checkCircleCollision(float x1, float y1, float r1, float x2, float y2, float r2) { return Math.sqrt(((x2 - x1) ^ 2) + ((y2 - y1) ^ 2)) <= (r1 + r2); }
(make sure you specify them to indicate :-)
However, your code is still wrong.
As stated here , the Java ^ operator is intended for exceptional bitwise OR, and not exponentiation. Perhaps you want Math.pow() ?
Returns the value of the first argument raised to the power of the second argument.
public boolean checkCircleCollision(float x1, float y1, float r1, float x2, float y2, float r2) { return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)) <= (r1 + r2); }
Or you can also just use Math.hypot instead of riding yourself!
Returns sqrt (x ^ 2 + y ^ 2) without intermediate overflow or downstream.
public boolean checkCircleCollision(float x1, float y1, float r1, float x2, float y2, float r2) { return Math.hypot(x2 - x1, y2 - y1) <= (r1 + r2); }