# Unity3d OverlapSphere and raycasting problem

I have a grenade (rigidbody) which make a spherecast when it detonates. On each found colliders, i will make a raycast to check if it is visible to the grenade or not.

void Explode() {

foreach(Collider coll in colliders) {

// when the collider belongs to a player..
if(coll.transform.GetComponent<Player_Controller>() != null) {

RaycastHit hit;

// ..i want to check whether its behind an obstacle or not
if(Physics.Raycast(transform.position, (coll.transform.position - transform.position), out hit)) {

coll.transform.GetComponent<Player_Controller>().TakeDamage();

}

}

}

Destroy(gameObject);

}


My problem is i will get the collider for all players, but when i do the raycast from the grenade to the found collider, i only hit the environment i play in. So basically my map. The grenade is laying on the ground so maybe there is an error in my raycast direction.

Edit: I solved this, the raycast was pointing not at the very bottom of the collider instead a little bit below so it was under the ground. I havent seen it unless i draw a debug ray..

• If you have found an answer, write an answer and mark it accepted. – trollingchar May 30 at 11:39