I'm trying to create a collision detection method that checks if two of my objects (2 oval shaped uiimages) collide with each other. if they do it should set the BOOL value to YES otherwise it should set it to NO.

So far it just goes to the IF-statement that checks if Ruby1 is above Ruby2. It doesn't care if ruby1 is below ruby2 or even to the left or to the right of it. it just keeps going to that IF statement. and vice versa.

```
-(void)CollisionDetect{

//can't be colliding because Ruby1 is too far left of Ruby2

if( rubin1.frame.origin.x + rubin1.bounds.size.width < rubin2.frame.origin.x){

    CollisionRubies = NO;
    NSLog(@"Collision left");
}

//can't be colliding because Ruby1 is too far right of Ruby2

if( rubin1.frame.origin.x > rubin2.frame.origin.x + rubin2.bounds.size.width){

    CollisionRubies = NO;
    NSLog(@"Collision right");
}

//can't be colliding because Ruby1 is too far below Ruby2

if( rubin1.frame.origin.y + rubin1.bounds.size.width < rubin2.frame.origin.y){
    CollisionRubies = NO;
    NSLog(@"Collision below");
}

//can't be colliding because Ruby1 is too far above Ruby2

if( rubin1.frame.origin.y < rubin2.frame.origin.y + rubin2.bounds.size.width){
    CollisionRubies = NO;
    NSLog(@"Collision above");
}

    if( rubin2.frame.origin.x + rubin2.bounds.size.width < rubin1.frame.origin.x){

    CollisionRubies = NO;
    NSLog(@"Collision left");
}

//can't be colliding because Ruby2 is too far right of Ruby1

if( rubin2.frame.origin.x > rubin1.frame.origin.x + rubin1.bounds.size.width){

    CollisionRubies = NO;
    NSLog(@"Collision right");
}

//can't be colliding because Ruby2 is too far below Ruby1

if( rubin2.frame.origin.y + rubin2.bounds.size.width < rubin1.frame.origin.y){
    CollisionRubies = NO;
    NSLog(@"Collision below");
}

//can't be colliding because Ruby2 is too far above Ruby1

if( rubin2.frame.origin.y < rubin1.frame.origin.y + rubin1.bounds.size.width){
    CollisionRubies = NO;
    NSLog(@"Collision above");
}

//if we get here, the two rects MUST be colliding
CollisionRubies = YES;
NSLog(@"Collision detected");

```

}

if the BOOL value is NO then ruby1 will move to that position as shown in the code below otherwise it will stop moving until it detects that ruby2 isn't in front of it. and vice versa.

```
-(void)dispatchTouchEvent:(UIView *)theView toPosition:(CGPoint)position{
// Check to see which view, or views,  the point is in and then move to that position.
if (CGRectContainsPoint([rubin1 frame], position)) {

    if(!CollisionRubies){

        rubin1.center = position;
    }
     if (CGRectContainsPoint([rubin2 frame], position)) {

    if(!CollisionRubies){

        rubin2.center = position;
    }

}

```

the collision detection method is called from the touchesmoved method

```
 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

[self CollisionDetect];

 NSLog(@"touchesMoved");
 if(!GamePaused){
         // Enumerates through all touch objects
         for (UITouch *touch in touches) {

             // Send to the dispatch method, which will make sure the appropriate subview is acted upon
             [self dispatchTouchEvent:[touch view] toPosition:[touch locationInView:self.view]];
         }
 }

```

What am I doing wrong? 

\*\**\**\*\**\**\*\**\**\**UPDATE****\**\*\**\**\*\**\**\*\**\**\*\**\**\*\**\**\*\**\**\*\**\**\*\**\**\*\**\**\*\*\***

```
-(void)CollisionDetect{

```

//can't be colliding because Ruby1 is too far left of Ruby2

if( rubin1.frame.origin.x + rubin1.bounds.size.width < rubin2.frame.origin.x){

```
CollisionRubies = NO;
NSLog(@"Collision left");

```

}

//can't be colliding because Ruby1 is too far right of Ruby2

else if( rubin1.frame.origin.x > rubin2.frame.origin.x + rubin2.bounds.size.width){

```
CollisionRubies = NO;
NSLog(@"Collision right");

```

}

//can't be colliding because Ruby1 is too far below Ruby2

else if( rubin1.frame.origin.y + rubin1.bounds.size.width < rubin2.frame.origin.y){
 CollisionRubies = NO;
 NSLog(@"Collision below");
}

//can't be colliding because Ruby1 is too far above Ruby2

else if( rubin1.frame.origin.y < rubin2.frame.origin.y + rubin2.bounds.size.width){
 CollisionRubies = NO;
 NSLog(@"Collision above");
}

```
if( rubin2.frame.origin.x + rubin2.bounds.size.width < rubin1.frame.origin.x){

CollisionRubies = NO;
NSLog(@"Collision left");

```

}

//can't be colliding because Ruby2 is too far right of Ruby1

else if( rubin2.frame.origin.x > rubin1.frame.origin.x + rubin1.bounds.size.width){

```
CollisionRubies = NO;
NSLog(@"Collision right");

```

}

//can't be colliding because Ruby2 is too far below Ruby1

else if( rubin2.frame.origin.y + rubin2.bounds.size.width < rubin1.frame.origin.y){
 CollisionRubies = NO;
 NSLog(@"Collision below");
}

//can't be colliding because Ruby2 is too far above Ruby1

else if( rubin2.frame.origin.y < rubin1.frame.origin.y + rubin1.bounds.size.width){
 CollisionRubies = NO;
 NSLog(@"Collision above");
}

else{
//if we get here, the two rects MUST be colliding
CollisionRubies = YES;
NSLog(@"Collision detected");
}