# I need help with collision detection in clone game

**URL:** <https://discourse.processing.org/t/i-need-help-with-collision-detection-in-clone-game/46723>\
**Category:** Coding Questions\
**Created:** [July 13, 2025, 10:33pm UTC](https://discourse.processing.org/t/i-need-help-with-collision-detection-in-clone-game/46723 "2025-07-13T22:33:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 14, 2025, 1:50am UTC](https://discourse.processing.org/t/i-need-help-with-collision-detection-in-clone-game/46723/2 "2025-07-14T01:50:38Z")

</div>

Hello @PaddedMellie ,

Your bullets and ship will never be exactly at the same position!

Use _println()_ statements to see what is going on.  
Add a visual queue such as _background()_ to flash when there is a collision.

This code is only comparing along the y-axis when they are within 30 pixels and flashes (code works here):

```auto
  void bulletCollision(){
   //println(x, y);
   //println(shipX, shipY);
   println(p.y, this.y);
   println(shipY);
   println();
   
   //if(x == shipX && y == shipY) // May never see this condition!
   {
   if(abs(y - shipY) <30) // If within 30!
     {
     println("COLLISION");
     background(255);
     }
   }
  }

```

Above is only intended to help get you started with troubleshooting tips.  
It can be easily modified for x position.

Note:

I reduced the spaceships to one for testing:  
`Spaceships[] ships = new Spaceships[1];`

It works (detects collision) with one spaceship or first spaceship if you have more than one.

Also look here for guidance:  
_[Guidelines—Asking Questions](https://discourse.processing.org/t/guidelines-asking-questions/2147/1)_

Keep at it!

`:)`

---

_[View the full topic](https://discourse.processing.org/t/i-need-help-with-collision-detection-in-clone-game/46723)._
