• Create Account

### #ActualBlack-Rook

Posted 07 October 2012 - 11:09 PM

There are a few ways to do collision detection.

Grids, bounding box, pixel perfect, ect...

For something like this, I would learn bounding box collision if you're new to how collision works.

Your main objective here is to get the x and y values for each object, and their current height and width to create a top, bottom, left, and right. Now, you will be checking if one box (or several) collide with another box, which means collision has been detected. I will show you a basic example.

Ball:

Ball_BB_Top = Ball_Y
Ball_BB_Left = Ball_X
Ball_BB_Right = Ball_Width + Ball_BB_Left
Ball_BB_Bottom = Ball_Height + Ball_BB_Top

Now to detect if collision is true, you would simply have basic check seeing if anything collides.

{
Collision = true;
}

Edit: The most important thing to never forget!!! You must update these values for each frame, or your bounding boxes will have incorrect values. So make a function to update the values before checking for collision.

### #1Black-Rook

Posted 07 October 2012 - 11:07 PM

There are a few ways to do collision detection.

Grids, bounding box, pixel perfect, ect...

For something like this, I would learn bounding box collision if you're new to how collision works.

Your main objective here is to get the x and y values for each object, and their current height and width to create a top, bottom, left, and right. Now, you will be checking if one box (or several) collide with another box, which means collision has been detected. I will show you a basic example.

Ball:

Ball_BB_Top = Ball_Y
Ball_BB_Left = Ball_X
Ball_BB_Right = Ball_Width + Ball_BB_Left
Ball_BB_Bottom = Ball_Height + Ball_BB_Top

Now to detect if collision is true, you would simply have basic check seeing if anything collides.