[Solved]Get the position of where objects collide

Get help using Construct 2

Post » Fri Apr 05, 2013 11:02 am

Hello,

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

Biino2013-04-06 09:01:50
B
10
S
1
Posts: 26
Reputation: 1,007

Post » Fri Apr 05, 2013 11:32 am

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.
B
56
S
15
G
10
Posts: 910
Reputation: 11,942

Post » Fri Apr 05, 2013 12:48 pm

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.
B
16
S
4
G
1
Posts: 332
Reputation: 3,016

Post » Fri Apr 05, 2013 1:12 pm

good question, I deal with it using detectors, but if you find a solution, please, don't forget to say @Telles0808 on your reply =]
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Fri Apr 05, 2013 10:01 pm

@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.zatyka2013-04-06 05:00:11
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Sat Apr 06, 2013 3:54 am

@zatyka thank you dude.
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Sat Apr 06, 2013 4:17 am

@TELLES0808

No problem. I would have added your user name to my last post, but for some reason I thought you were looking for a solution for polygons and not lines. Anyway, I hope my demo helped.
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Sat Apr 06, 2013 9:01 am

@zaytka, thanks a lot, if you explain it like this it is indeed not that difficult haha :)

B
10
S
1
Posts: 26
Reputation: 1,007

Post » Sat Apr 06, 2013 12:31 pm

@zatyka: thanks alot man, yesterday I was on math lesson to be able to find equations such as these :)
B
16
S
4
G
1
Posts: 332
Reputation: 3,016


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests