when trying to detect if im grounded or not i use the code
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 1f, layer);
if(hit.collider != null) {
isGround = true;
}
else {
isGround = false;
}
but it does not detect the ground and says its null everytime
As I noted here:
Yet we know this stuff works, so isolate, isolate, isolate. Make a fresh scene, one sprite, with collider, layers marked exactly as you want, and get with the script to get it working.
Once that works, bisect back to your project and find what is missing. Nobody here staring at these little tiny text boxes can tell you, honest!
The difference between Layers vs LayerMasks:
“There are 10 types of people in this world: those who understand binary, and those who don’t.”
we KNOW this works, so back up.
Type in hard numbers (not transform.position) and hard layer masks.
This is fundamental Engineering 101: when something doesn’t work, remove stuff until you can get the barest minimum working. Start from the sample code in the docs… or perhaps a tutorial.