2d collision detection methods

Started by
4 comments, last by henry5674 18 years, 3 months ago
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!
Advertisement
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.
two rectangles wouldn't collide at a point, assuming they are alligned the same. you should be returning a rect as the overlap.

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.
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.

Everything is better with Metal.

thanks oliii i will focus my study on vector math and go from there

This topic is closed to new replies.

Advertisement