0
\$\begingroup\$

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() { Collider[] colliders = Physics.OverlapSphere(transform.position, radius); 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..

\$\endgroup\$
1
  • 3
    \$\begingroup\$ If you have found an answer, write an answer and mark it accepted. \$\endgroup\$ Commented May 30, 2019 at 11:39

1 Answer 1

1
\$\begingroup\$

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. Because my character has an empty gameobject representing its head, i point at this instead to be sure its above the ground.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.