# Using dist(); for collision detection

**URL:** <https://discourse.processing.org/t/using-dist-for-collision-detection/40050>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 7, 2022, 11:33am UTC](https://discourse.processing.org/t/using-dist-for-collision-detection/40050 "2022-12-07T11:33:32Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![LeckereKrokette](https://avatars.discourse-cdn.com/v4/letter/l/b77776/32.png) [@LeckereKrokette](https://discourse.processing.org/u/LeckereKrokette)\
**Post date:** [December 7, 2022, 11:33am UTC](https://discourse.processing.org/t/using-dist-for-collision-detection/40050/1 "2022-12-07T11:33:32Z")

</div>

Hello processing community. I want to make a mini game where you control a ellipse and have to avoid other ellipse. I first wanted the “opponents” to repel each other. For this I initialized 10 ellipses in an array. But when I try to use the dist function to see if the radius overlaps, it only shows that the dist function doesn’t expect a float parameters. Are there other solutions or can you convert your array in some way so that it is still possible to use dist.

```auto
int ballCount = 10;
float r = 60;
float angle=10;
float[] x = new float[ballCount];
float[] y = new float[ballCount];
float[] xSpeed = new float[ballCount];
float[] ySpeed = new float[ballCount];

void gegner(){
  for(int j = 0; j < ballCount; j++){

    x[j] += xSpeed[j];
    if(x[j] < 133 || x[j] > width-130){
      xSpeed[j] *= -1;
    }

    y[j] += ySpeed[j];
    if(y[j] < 133 || y[j] > height-130){
      ySpeed[j] *= -1;
    } 
    
    
    if(dist(x=xSpeed, y=xSpeed, x[j], y[j]) < r)

{
   if(xSpeed >0){
     xSpeed = -1;
    }
   else if(xSpeed < 0){
      xSpeed = 1;
    }
    if(ySpeed > 0){
      ySpeed = -1;
    }
    else if(ySpeed < 0){
      ySpeed = 1;
    }
    
 }
  
  stroke(0);
fill(0);
    ellipse(x[j], y[j],r,r);
    fill(#2BFF03);
    rect(x[j], y[j],20,20);  
}}

void setup(){
size (800,800);
for(int j = 0; j < ballCount; j++){
    x[j] = random(200,800);
    y[j] = random(200,800);
    xSpeed[j] = random(2.5, 3);
    ySpeed[j] = random(2.5, 3);}
}

void draw() {
  background(0);

gegner();

}

```

---

_[View the full topic](https://discourse.processing.org/t/using-dist-for-collision-detection/40050)._
