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
}
}