How do I get overlap coordinates?

0 favourites
  • 5 posts
  • Hello.

    Is there any (built-in) way to get the x, y position of where two objects intersect?

  • No, even internally c2 only checks if there is an overlap not where they collide.

  • Okay, no big. Thx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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))

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)