How do I get overlap coordinates?

Get help using Construct 2

Post » Thu Aug 28, 2014 3:55 pm

Hello.

Is there any (built-in) way to get the x, y position of where two objects intersect?
B
39
S
16
G
6
Posts: 542
Reputation: 7,617

Post » Thu Aug 28, 2014 5:18 pm

No, even internally c2 only checks if there is an overlap not where they collide.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Thu Aug 28, 2014 8:34 pm

Okay, no big. Thx :)
B
39
S
16
G
6
Posts: 542
Reputation: 7,617

Post » Sun Aug 31, 2014 9:13 pm

@ErekT
You can calculate it though. The complexity depends on what shapes you use. Of course an overlap seldom occurs at one spot unless they are just touching.

The simplest would be a circle circle collision. The collision normal would be the angle from circleA to circleB.
Normal_AtoB = angle(circleA.x,circleA.y,circleB.x,circleB.y)

Then the point on CircleA would be (CircleA.x+radiusA*cos(Normal_AtoB), CircleA.y+radiusA*sin(Normal_AtoB))
And the point on circleB would be (CircleB.x+radiusB*cos(Normal_AtoB+180), CircleB.y+radiusB*sin(Normal_AtoB+180))
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Wed Sep 03, 2014 11:16 pm

Thanks man, much appreciated! It's for a side-view platformer so all I really need is the x position of impact points to spawn a particle effect. Projectiles travel at a straight horizontal line. Well not actually travelling, I'm just spawning a very long hitbox and then check to see if anything overlaps with it. For now the particle effect gets set to the target x position +/- a small offset which works okay. I'll keep your method in mind for future needs though :)
B
39
S
16
G
6
Posts: 542
Reputation: 7,617


Return to How do I....?

Who is online

Users browsing this forum: 25games, Artcadev, brunopalermo, Google [Bot], MaxxMunnn, mcscooter, Soluna Software and 25 guests