# How to make balls in an array bounce of each other?

I just started coding and I’m sorry if i made your eyes bleed

this my collison detection

``````class Collisions {
float dir;
Collisions () {
}
void BallCollide(float x, float y, float d) {
for (int i = 0; i < Ball.length; i++) {
if (dist(x, y, Ball[i].x, Ball[i].y) >0 && dist(x, y, Ball[i].x, Ball[i].y) < Ball[i].radius *2) {
dir = -d;
} else {
dir = d;
}
}
}
float getDir() {
return dir;
}
``````

Hi @Eshad can you explain what’s your code is doing so far? I would recommend looking into this tutorial as you need a little bit more physics to pull this off https://channel9.msdn.com/Series/Sketchbooktutorial/Simple-Collision-Detection-and-Response hope this helps There are several great collision detection tutorials in Processing.

There is a single extensively annotated example, CircleCollision, which deals with the balls array issue (although it isn’t a class-based solution):

And there are two full walkthrough tutorials:

1. Collision Detection (Jeff Thompson) http://www.jeffreythompson.org/collision-detection/

2. Collision Detection (Kevin Workman) http://happycoding.io/tutorials/processing/collision-detection