# Collision between moving objects

**URL:** https://discourse.processing.org/t/collision-between-moving-objects/7274
**Category:** Coding Questions
**Created:** [January 7, 2019, 5:19pm UTC](https://discourse.processing.org/t/collision-between-moving-objects/7274 "2019-01-07T17:19:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bernbernm](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bernbernm](https://discourse.processing.org/u/bernbernm)
#### Post date: [January 7, 2019, 5:19pm UTC](https://discourse.processing.org/t/collision-between-moving-objects/7274/1 "2019-01-07T17:19:04Z")

</div>

Hey i’m using PImage to make my game and i’m trying to record a collision between my caterpillar and the birds to reset the score back to 0 if it happens.  
I know how to record collision with basic shapes such as rect but do i need to create a new variable for my each of my classes to check the positions?

The caterpillar is moved by mouseX and Y and the birds are an array that each move on a random y value and with this code `void move() {

```
x= x + xspeed * direcction;
if (x>1280) { 
  direcction=-1;
} else if (x<0) {
  direcction=1;
}`
```

---

<div class="post-metadata">

### Author: ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)
#### Post date: [January 7, 2019, 11:47pm UTC](https://discourse.processing.org/t/collision-between-moving-objects/7274/2 "2019-01-07T23:47:46Z")

</div>

The only variables you need to check collision are positional variables such as X and Y and dimensions. Since your using PImage, you can get the exact dimensions pretty easily

float playerWidth = image.width;  
float playerHeight = image.height;

Also if you’re stuck on collision detection, I’d bookmark this link

> **[Collision Detection](http://www.jeffreythompson.org/collision-detection/rect-rect.php)**
>
> An online book about collision detection using Processing.
