# 2d collision detection methods

This topic is 4733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi everybody! i am developing my first 2d game engine in visual C++ and am having problems with my collision detecting code. I want to be able to detect a point of collision between two rectangles. Because they may be moving at speed i can't just check for overlaps as they may have passed through each other. i have to be honest and admit my math is poor so if someone can tell which subjects to study i'll go do my homework.i like idea of using vectors (i have a basic understand of them) but apart from that i am struggling! any help more than welcome!

##### Share on other sites
Well, it's not terribly hard, it just requires some thought. If you'd like, I have some code that calculates when two rects collide which I posted in this thread. It's fairly well commented, so you could probably figure a few things out by looking at it.

##### Share on other sites
two rectangles wouldn't collide at a point, assuming they are alligned the same. you should be returning a rect as the overlap.

##### Share on other sites
hi guys
Thanks for the reply! Bytecoder i will study your code, i think i can figure it out. Where can i find the vector2d class? is it in the directx lib.
Minamur u are right there is no single point of collision,my existing method uses y=mx+b to find a collision by testing each point on a line then returns an overlap if there is one. With a small slope it's not accurate enough to predict the side of collision,so i need to calculate where rect1 begins collision with rect2 and then step through from that position to give an overlap.

##### Share on other sites
you should learn vector maths is you wanna do arbitrary and more advanced collision detection. It's an easy concept, and is the basis of all physics / collisions in games.

Vectors and Matrices: A Primer, by Phil Dadd

using slopes, linear equations and trigonometry will be just too much of a hassle as soon as you want to do something a bit advanced. Even simple stuff is easier with basic vector projection.

##### Share on other sites
thanks oliii i will focus my study on vector math and go from there

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013596
×