How do I get coordinates of collision?

Get help using Construct 2

Post » 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,458

Post » 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
387
S
229
G
87
Posts: 24,245
Reputation: 192,160

Post » 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
131
S
29
G
81
Posts: 5,328
Reputation: 56,630

Post » 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.

Image

And if they are different sizes you can probably add some math magic and calculate that as well. :D
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » 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,458

Post » 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
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » 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?
are you saying i need chipmunk physics instead? i dont know about this behavior.
B
10
S
4
G
3
Posts: 223
Reputation: 3,458

Post » 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
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » 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,458

Post » 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
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest