I have the following simple raycast from a capsule on a cube:
bool hit = Physics.Raycast
(transform.position, Vector3.down,
jumpSettings.groundJumpDistanceCheck,
jumpSettings.layerMask);
print(hit);
When my layerMask
is 8 (terrain), I have set my layer on my cube and my groundJumpDistanceCheck
is 2. Then my hit
is false.
When my groundJumpDistanceCheck
is set to Infinity. Then my hit
is still false.
However when I remove the distance parameter:
bool hit = Physics.Raycast
(transform.position, Vector3.down,
/* jumpSettings.groundJumpDistanceCheck, */
jumpSettings.layerMask);
print(hit);
Then hit
returns true. This is odd for me, as far as I know when you exclude the distance parameter it's supposed to be Infinity by default. But when I explicitly give Infinity as the distance, it returns false.
I have also used the following code in an attempt to debug my issue, using the desired distance 2f
Debug.DrawRay(transform.position,
Vector3.down * jumpSettings.groundJumpDistanceCheck, Color.red, 60f);
As you can see, the ray does intercept the cube.
I need the reycast to return true with a distance of 2f
.
jumpSettings.layerMask
field - either in the inspector or in code. A common error is to use the layer index as a layer mask, instead of setting the corresponding bit in the mask bitfield, so showing where you provide the value can eliminate this case. \$\endgroup\$