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
38
S
16
G
6
Posts: 537
Reputation: 7,582

Post » Thu Aug 28, 2014 5:18 pm

No, even internally c2 only checks if there is an overlap not where they collide.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Thu Aug 28, 2014 8:34 pm

Okay, no big. Thx :)
B
38
S
16
G
6
Posts: 537
Reputation: 7,582

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
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

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
38
S
16
G
6
Posts: 537
Reputation: 7,582


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests