How do I get coordinates of collision?

Get help using Construct 2

» Thu Oct 08, 2015 11:52 pm

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?
B
10
S
4
G
3
Posts: 223
Reputation: 3,463

» Fri Oct 09, 2015 10:51 am

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.
Scirra Founder
B
408
S
242
G
92
Posts: 24,910
Reputation: 198,648

» Fri Oct 09, 2015 10:59 am

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 your vision so exceeds your ability, then look to something closer.
Moderator
B
140
S
31
G
88
Posts: 5,735
Reputation: 61,456

» Fri Oct 09, 2015 12:47 pm

cs2curious wrote: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.
B
45
S
12
G
3
Posts: 1,209
Reputation: 7,537

» Fri Oct 09, 2015 7:12 pm

zenox98 wrote: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.
B
10
S
4
G
3
Posts: 223
Reputation: 3,463

» Fri Oct 09, 2015 8:04 pm

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
Last edited by R0J0hound on Mon Apr 03, 2017 9:05 pm, edited 1 time in total.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

» Fri Oct 09, 2015 8:39 pm

That looks nifty. If I am using physics, and things are bouncing off of each other will that still work?
B
10
S
4
G
3
Posts: 223
Reputation: 3,463

» Fri Oct 09, 2015 9:03 pm

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.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

» Sat Oct 10, 2015 3:22 am

yeah it wont work with default physics because they bounce off before they overlap. I guess I might need to get chipmunk physics =/
B
10
S
4
G
3
Posts: 223
Reputation: 3,463

» Sat Oct 10, 2015 7:14 am

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.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

Next