Skip to main content
gamedev.net
🔒 Locked

Collision Detection

Started by iSlade 3 replies 550+ views
Original Post
iSlade
iSlade
I have two triangles, each made up of three points (each point containing an x and y value). i want to tell if they are touching each other. this is for a game i am making that is like Grand Theft Auto (top down car driving) that i am making to teach myself stuff. I have everything i could find, but havn''t successfully made any collision detection methods that work. Any help would be appreciated.
Zeusel
Zeusel
the way i would do it: a sphere around the triangle centre! if the others triangles sphere touches the other(distance tri a to tri b < radius ofthe sphere: it touches) do btter detection! the better detection works with 3d planes, how exactly, i ont know!
"be fair! ... always"Zeusel
johnb
johnb
For just two triangles you could try working out the points of intersections of the edges and see of any overlap or meet. E.g. take an edge from each triangle and work out where the lines they are on meet. If this point exists and if it is between the ends of both lines then the lines cross or meet. If not they don''t.

Repeat this for all possible pairs (there are 9 = 3 x 3 of them) and if any meet/cross then the triangles meet/cross. If not then they are either completely seperate or one is inside the other (which is easy to check).

This is straightforward, but it''s a lot of checking to do. It''s OK for just a pair of triangles but for more complex shapes or lots of shapes it is a lot more expensive, in which case a more efficient but more sophisticated algorithm might be better.
John BlackburneProgrammer, The Pitbull Syndicate
iSlade
iSlade
At this stage I don''t mind if i don''t fully understand how the algorithm works, so even if there was one i could download and use (only problem is that while i am learning C++ very slowly, this program is actually using visual basic).

This sort of collision detection seems common and I would have thought it would be easy to find a suitable method somewhere, but i guess not.

If i have two lines, how do i check if they overlap, i never paid any attention in Maths C
Profus
Profus
have a look at this thread.

------------------------------------------------------------
"To a computer, chaos is just another kind of order."
------------------------------------------------------------"To a computer, chaos is just another kind of order."

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.