Jump to content
  • Advertisement
Sign in to follow this  
henry5674

2d collision detection methods

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!