Detect full overlap/collision event

0 favourites
  • 4 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • 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?

  • Try the distance expression.

    System ; Compare two values;

    distance(ball.X,ball.Y,hole.X,hole.Y)< 20 ;

         Do something ;

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • Changing the bounding poly worked perfectly... I can't believe I didn't find this before.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)