Detect full overlap/collision event

Get help using Construct 2

Post » Mon Dec 30, 2013 1:12 am

I have a scenario where I want to know if one element is completely (or mostly) overlapping another element.

The best way I can describe this is to imagine a top-down view of a mini-golf course... I want to know when the "centroid" of the ball is within the hole element's circumference... hence a completed hole.

Collision doesn't work because the ball would be considered "in" if the edges touch.

Overlapping doesn't work because the ball would be considered "in" if a fraction of the ball covers the hole.

In my case the "ball" I'm trying to get in the "hole" is a ~20px dia. ball in a ~25px dia hole.

Is there a built in event that I can use to achieve this? or do I need to roll my own... testing the X,Y of my "ball" vs. the X,Y +/-5px of the hole?
B
7
S
2
G
4
Posts: 9
Reputation: 2,963

Post » Mon Dec 30, 2013 2:06 am

Try the distance expression.

System ; Compare two values;
distance(ball.X,ball.Y,hole.X,hole.Y)< 20 ;
     Do something ;
B
10
S
2
G
1
Posts: 202
Reputation: 1,545

Post » Mon Dec 30, 2013 2:30 am

Or, if all else fails, you can shrink the bounding box of the hole element and place it in the center of the sprite. That way, you can just set it to on collision, and it will trigger when the ball looks like its within the hole.

It's technically cheating, but I won't tell.
B
15
S
4
G
1
Posts: 168
Reputation: 2,177

Post » Mon Dec 30, 2013 3:16 am

Changing the bounding poly worked perfectly... I can't believe I didn't find this before.
B
7
S
2
G
4
Posts: 9
Reputation: 2,963


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], htmlgames and 5 guests