How do I retrieve collision point coordinate?

Just started using Construct 2? Post your questions here

Post » Wed Dec 31, 2014 2:56 pm

When there is collision happens, there is a point of collision. What expression should i use to retrieve the coordinate of that point?
B
17
S
4
G
1
Posts: 203
Reputation: 1,583

Post » Wed Dec 31, 2014 7:38 pm

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:
viewtopic.php?f=147&t=115529&p=831167&hilit=point+of+collision#p831167
viewtopic.php?f=147&t=114738&p=824528&hilit=point+of+collision#p824528

Here is a capx of resolving a collision between a circle and boxes.
viewtopic.php?f=147&t=95108&p=736233&hilit=wall+slide#p736233
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.
behavior-chipmunk-physics_t110815
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Wed Dec 31, 2014 8:15 pm

thx for the information, just wondering if it is not a perfect circle and square shape. Like an aeroplane shape.
B
17
S
4
G
1
Posts: 203
Reputation: 1,583

Post » Wed Dec 31, 2014 9:25 pm

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:
You do not have the required permissions to view the files attached to this post.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Thu Jan 01, 2015 11:09 am

it would be cpu intensive, but thx for the method!
B
17
S
4
G
1
Posts: 203
Reputation: 1,583

Post » Thu Jan 01, 2015 5:42 pm

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.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest