# Collision Detection - Intersecting Paths

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

## Recommended Posts

Hey all, If you have two objects travelling perpindicular to eachother such that they will intersect, how do you catch this overlap when the objects are moved? The problem arises because one object in the list is going to be moved before the other.
This Frame:

|
-+-o
|
o

Next Frame (No Collision):
o

o

How do you do it? Thanks.

##### Share on other sites
I think you've used the most simple way of detect collisions:

if(object.x > 100) //collision

This kind of collision detection is not accurate.It works on some cases but many times the user can see the problems of the collsion. When I was a begginer at collision detection, I used this method but I found the problems and later a developped one which is too much better. It works this way: you must have the position and the previous position of the objects.This way, you'll have a 'trajectory line' for this one.Then, what you must do is calculate the intersection between the trajectory lines. If they intersect, a collision happened. Did you understand me?!?I hope yes :)...

To calc the intersection point between two lines you'll need a bit of analitic geometry. You'll use the 'segment formula'.

y = m*x + n

Where m is the angular coeficient of the segment(the tangent of the angle the segment does with the X axis), n is the linear coefficient(the point where the segment intersects the Y axis) and x and y are the coordinates of any point in the segment.

So you have 2 lines.Lets calc the instersection point (Ix,Iy):

Ix = (m2 - m1)/(n1 - n2);//I will not explain why this formula here...If you wanna know analize the segment formula...

Iy = m1 * Ix + n1;//you can use this
Iy = m2 * Ix + n2;//or this...you'll get the same results

Using the methods described above you get the intersection point(Ix,Iy).
Did you understand?!?!? I hope you've taken the way!...

Using this the collision detection will not fail...after that, you can put the objects in the correct positions they should be...use you creativity to implement many things using this formula.....

Cya....

##### Share on other sites
Hey guys,

I just read what xissberg said....and it sounds fair enough, but I wanted to add a question/comment.

Xissberg says that if the lines intersect, then a collision has occured. The objects paths could intersect without a collision if they arrived at the collision point at different times. Wouldn't it be a good idea (depending on how fast you're objects are moving i guess) to check that they occupied the intersection point at the same time? (Off the top of my head, you could do some simple interpolation with the time delta and the displacement delta.)

I know this probably seems obvious to most of you, but im no expert and would be interested to know if there is a standard way of doing this.

James

##### Share on other sites
Quote:
 Wouldn't it be a good idea (depending on how fast you're objects are moving i guess) to check that they occupied the intersection point at the same time?
You're correct, just intersecting the segments won't give accurate results, so the problem has to be formulated a little differently.

The more accurate formulation of the problem isn't of much use with points, as they will rarely if ever actually hit each other when in motion. With circles, spheres, and other objects however there are clear solutions to the 'first time of intersection' problem.

I'll also mention that the y=mx+b form is not particularly useful or stable for these sorts of purposes, and that the line intersection problem is better solved in normal-distance or parametric form instead.

##### Share on other sites
See my posts here.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 27
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634101
• Total Posts
3015528
×