I hope someone can help me. I'm drawing two lines in construct 2 and I want to spawn an object on the place where the 2 lines collide.

Here is an image to make it clearer

10 posts
• Page **1** of **1**

This is something I've had to deal with a number of times, and for the life of me I can't figure out how to do it. In the past I've resorted to certain objects being made up of nine different collision boxes to get something workable, which obviously isn't appropriate for every situation.

If anyone can offer advice, I'd gladly listen to it, too.

If anyone can offer advice, I'd gladly listen to it, too.

**Posts:**912**Reputation:**12,061

B

57
S

15
G

10
For these kinds of situations I decided to take math lessons. It is possible by using various formulae. You can formulate a line if you know positions of two dots on it. You can do this for two lines and then use the two functions in a mathematical expression to decide if the collide and where they collide.

I am not there yet but I will surely go. In the meantime, it seems I will have to fiddle with various algorithms and values in them.

For now, you could use a grid, and then check each square to see if they are colliding with both the lines, but this would cause problems with low-angle crossings. If you are going for angles closer to 90, it should give an estimation. Even if you got more than one crossing grid square, you could just find the middle point between their locations to increase accuracy.

I am not there yet but I will surely go. In the meantime, it seems I will have to fiddle with various algorithms and values in them.

For now, you could use a grid, and then check each square to see if they are colliding with both the lines, but this would cause problems with low-angle crossings. If you are going for angles closer to 90, it should give an estimation. Even if you got more than one crossing grid square, you could just find the middle point between their locations to increase accuracy.

**Posts:**332**Reputation:**3,097

B

17
S

4
G

1
@Biino

@Windwalker

It's not terribly difficult to find the intersection point of 2 lines:

You can use each "line" object's angle and position to determine its straight-line equation. From there, use the two equations to solve for the same x and y.

Demo

Capx

This method will only work for straight lines. Unfortunately finding the intersection point of polygons is a bit outside my mathematical comfort zone... at least for now. It would be handy if there was a system expression for LastCollisionX and LastCollisionY. I don't know how difficult it would be to implement, but I do know it's a lot easier to detect*if* polygons collide rather than *where*.

You'd be surprised how often math is used in creating games. Knowing basic algebra, trig, and geometry has helped me on several occasions. If you're interested in brushing up on the subject, there's a myriad of resources online.zatyka 2013-04-06 05:00:11

@Windwalker

It's not terribly difficult to find the intersection point of 2 lines:

You can use each "line" object's angle and position to determine its straight-line equation. From there, use the two equations to solve for the same x and y.

Demo

Capx

This method will only work for straight lines. Unfortunately finding the intersection point of polygons is a bit outside my mathematical comfort zone... at least for now. It would be handy if there was a system expression for LastCollisionX and LastCollisionY. I don't know how difficult it would be to implement, but I do know it's a lot easier to detect

You'd be surprised how often math is used in creating games. Knowing basic algebra, trig, and geometry has helped me on several occasions. If you're interested in brushing up on the subject, there's a myriad of resources online.

**Posts:**339**Reputation:**11,406

B

51
S

15
G

8
**Posts:**26**Reputation:**1,007

B

10
S

1
10 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: MadSpy and 7 guests |