This exact code (except for the .rigidbody) worked wonderfull when i tried to hit box.colliders with it. Only thing I changed was turning the box.collider into a rigidbody and suddenly it doesn’t react at all. Anybody any idea wtf is going on ?
if (Physics.Raycast(transform.position, transform.up, out hit, lookingDistance)){
if (hit.rigidbody){ Debug.Log("Da");}
}
A Rigidbody and a Collider are not swappable- they aren’t the same thing, they just both have to do with the physics engine. A Rigidbody says “the physics engine should track or control this object, and allow it to interact with other physics objects”, while a Collider says “this is the shell that serves as a physics obstacle”. A moving object that needs to collide with other objects needs both. A static object that other objects collide with only needs to have a Collider (the other objects need a Rigidbody AND Collider to do the colliding).
A physics raycast doesn’t hit Rigidbodies on their own (they have no ‘shell’ defined to hit), the “RaycastHit” objects they produce just has a shortcut property that’s exactly the same as calling GetComponent() on the colliding object. If the hit objects has no Rigidbody, because it’s stationary, hit.rigidbody will be null. If an object has a Rigidbody but no Colliders, it cannot collide with anything, and it cannot be hit by raycasts- this is likely only useful for flying objects that need to be affected by physics for visual reasons (like certain special affects), but which don’t actually affect anything else in the scene.
Hope that helps!