Raycast can not detect collider
My bullet can not detect the collider and raycast can not detect the collision. It's very weird since the only way to get a message on the console is whenever I shoot bullets within the range of my terrain(either on or above), I instantly get "Terrain" printed on my console, but the raycast cannot detect any other objects and print anything, and if I go out of the range and shoot at a sphere, nothing gets printed.
void Update () {
if (Input.GetKey(KeyCode.KeypadEnter) && counter > delayTime)
{
Instantiate(bullet, transform.position, transform.rotation);
counter = 0;
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
{
Debug.Log(hit.collider.gameObject.name);
}
}
counter += Time.deltaTime;
}
}
Thanks!
Answer by RIw · Mar 30, 2016 at 02:19 PM
If I were you, I would do this a little different. Set your bullet's collider to "Trigger" and give to your collider "OnTriggerEnter" void in which you will check if the Player has entered the bullet's collider, if it has entered, then you can destroy the player.
Thanks for your reply. I just updated my question and what if I can only use raycast ins$$anonymous$$d of the trigger?
Why do you want to use the Raycasting? It has good worse precision than the trigger. Try to use the Linecast ins$$anonymous$$d of the Raycast and let me know if it was helpful or not.
Your answer
Follow this Question
Related Questions
How do I define the direction and speed of a projectile separately? (JS) 0 Answers
Bullets are firing in the wrong direction. 1 Answer
Make bullet face direction of movement 1 Answer
Health and Damage Script Not Working 2 Answers
am trying to instantiate a 3D object to fly in the direction where my mouse is pointing 0 Answers