How do I get coordinates of collision?

0 favourites
  • 13 posts
  • if I have two big objects collide is there a way to get the X,Y coordinates of where these two objects are hitting, or overlapping so I can add an effect there? like collision X, y ?

    or maybe there are some behaviors that can track collision points?

    Edit: or get nearest image point, or anything like this?

  • This is a common question, but collisions don't happen at a specific point - collisions are actually overlapping regions. It's also possible that the first tick objects start overlapping (where "On collision" triggers) there are multiple separate overlapping regions, so there's not even just one area.

    It's probably best just to estimate it by calculating a point at the edge of the object in the direction of the colliding object.

  • R0J0hound has posted a few useful posts on using both an iterative method and also the one below (just search for posts by him with subject collision point etc):

    Collision Point

    May or may not be useful.

  • if I have two big objects collide is there a way to get the X,Y coordinates of where these two objects are hitting, or overlapping so I can add an effect there? like collision X, y ?

    or maybe there are some behaviors that can track collision points?

    Edit: or get nearest image point, or anything like this?

    If your objects are the same size, this can easily be calculated like this.

    And if they are different sizes you can probably add some math magic and calculate that as well.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound has posted a few useful posts on using both an iterative method and also the one below (just search for posts by him with subject collision point etc):

    Collision Point

    May or may not be useful.

    Something to do with ray casting? not 100% sure how I would use that... maybe I need to marinate a bit.

  • If you use the chipmunk behavior it can give you this info.

    If one of the objects is a circle you could also do this:

    viewtopic.php?f=147&t=153479&p=967445&hilit=collision#p967445

    Another idea that would work ok in most cases is add an image point to every corner of the object's shape. Then loop over the image points and see if they overlap the other object. For every one that does get an average position and that will be your point of collision.

    https://www.dropbox.com/s/ndzxmp4mwc5sd ... .capx?dl=0

  • That looks nifty. If I am using physics, and things are bouncing off of each other will that still work?

    are you saying i need chipmunk physics instead? i dont know about this behavior.

  • You can still use that method with the built in physics.

    I'm saying if you used chipmunk physics instead there's an expression to get the point of collision under a "on post collide" condition.

  • yeah it wont work with default physics because they bounce off before they overlap. I guess I might need to get chipmunk physics =/

  • You may be able to work around that by resizing the sprites first so they overlap before that check. Then afterwards resizing them back.

    Or you could move the imagepoints a bit further off the collision polygon.

  • R0J0hound

    Bringing this post back to life. Your links is not working anymore. can you please share it again?

  • jogosgratispro

    Updated that chain of links.

  • R0J0hound

    Thank you man!

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