0 Favourites

How do I retrieve collision point coordinate?

  • When there is collision happens, there is a point of collision. What expression should i use to retrieve the coordinate of that point?

  • You'll have to calculate it manually. How hard it is to do that depends on the shapes.

    If you want the collision point of circles:

    Here is a capx of resolving a collision between a circle and boxes.

    You can calculate the collision point in event 10 with:

    Sprite.x + radius*cos(min_ang+180)

    Sprite.y + radius*sin(min_ang+180)

    I have also made a physics plugin with a "Post Collision" condition that you can use to get the collision point.

  • thx for the information, just wondering if it is not a perfect circle and square shape. Like an aeroplane shape.

  • Usually the method is to break the objects into convex shapes and find the collision points between them.

    Another method I've read about would be to cast rays in the direction of motion from the points of one object to another, then the shortest line would indicate the points that hit first.

    Here's a rough example of that:

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • it would be cpu intensive, but thx for the method!

  • You're welcome.

    There is a lot of ways this can be made faster. One is to not cast the rays as far, since far apart objects wouldn't be colliding. Also only lines that hit should be considered for picking the closest from. Actually you'd want to use math to calculate the raycast points which may be faster than doing a looping collision check, and will be a lot more accurate.

    Another thing you could do is only do this after a collision actually occurred. So the flow would be:

    1. object overlaps another.

    2. move object back to previous position

    3. Ray cast collision points to find point of collision.

    The only drawback of that is there is no expressions to access the collision points.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
217 18,521
humanescape's avatar
humanescape
Unread hot topic
99 10,127
karshinkoff's avatar
karshinkoff
Unread hot topic
56 4,727
MPPlantOfficial's avatar
MPPlantOfficial