Raycast tweaking

I have a problem with my raycasting sometimes doing two hits instead of one on my objects.

the situation is this, I have an object jumping from one platform to another. The raycast one the jumping object detects whenver it lands on a platform and gives the jumping object a velocity boost upon touch. (so it can continue jumping)

The problem is that the raycast on my juming object is sometimes detecting TWO hits when touching the platform instead of ONE. The counting for this is important to the gameplay, so this messes the game up!

How can I tweak the raycast so it will always and only detect ONE hit each time my jumping object lands on the platform?

You can either try debugging your game to find why it is hitting the object twice and solve the problem there or you can add a boolean variable to your script which triggers true on the first hit so it can’t go to subsequent hits.

I.e:

var hasHit = false;
if (raycast hits platform  !hasHit) {
    hasHit = true;
}

Solved it using the boolean tip you gave. So far so good.

Thank you :slight_smile: