c# layermask in raycasting doesn't work !!!

hi every body
i used code below to make a ray only collide with Ground Layer and go through every other object. but doesn’t work :

if (Physics.Raycast(transform.position, -Vector3.up, out hit,shadowRayMask.value))

any idea?

thank you for reply . The origin wasn’t my problem because ray could draw to infinity that time. but i found i must set Distance in ray casting . when my ray created, it stops until it collide with first object .

so the code is :
if (Physics.Raycast(transform.position, -Vector3.up, out hit,200, shadowRayMask)

I’d say that hard coding 1<<8 is bad practice. How do you even know that 8 is the layer number you want?

Anyway, what I usually do is:

LayerMask shadowRayMask = 1 << LayerMask.NameToLayer("WhateverYourLayerIsCalled")

if (Physics.Raycast(transform.position, -Vector3.up, out hit, shadowRayMask))//No need for the .value here

Also keep in mind that this will raycast from the exact position of your object. So if the object’s “pivot point” is at its base, then it could be just beneath the ground, meaning it will not hit anything. So you’d probably want to start at transform.position + Vector3.up or something.