Check if objects are touching at a specific time.

I am working on a golf type game where if the ball is resting on the green when it is hit then it shouldn’t rise off the green but stay down (aka the force applied is 0 in the Y). I have a stroke function for when the player hits the ball and in that I’m checking some bools to see if the ball is on the green, in sand, in rough. Each of those checks determines the possible force applied to the ball. The way it works is I have:

void OnCollisionEnter2D (Collision2D other) {
     if(other.collider.tag == "Green") {
          putting = true;
     } else if(other.collider.tag == "Sand") {
          bunker = true;
     } else if(other.collider.tag == "Rough") {
          rough = true;
     }

}

On Collision exit I set the appropriate bools to false and then when I run the stroke method I check those three bools first before applying the force. This works but I would like to find a way to only check my lie when I run the stroke method. So I want it to look something like

void Stroke(int direction) {
     if(rigidbody2d.isTouching(ObjectWithTag("Green")) {
          // Apply putting force
     }
}

Hi, as @robertbu said, you can use a circle collision check to return all the objects that the ball collides with. You could filter the results by the layer you use for the golf course’s geometry. As a side note, have you considered using a switch for processing the tags, easier to read/extend. I hope that helps =D