- Home /
Physhics.Raycast not working properely
Hello, I am making an FPS game and I'm using Raycasting as a way of hitting the enemy, but there's an issue when I start the game it detects that I hit enemy only 3 or 4 times, when I shoot again and I am for the enemy it ignoring him and it detects i am hitting a wall or a ground. Does anyone know what might be the issue of causing this?
Answer by kylecat6330 · Feb 11 at 06:33 PM
It is hard to say without seeing any of the code.
It may be that the raycast is not going in the direction it is intended to. Try using Debug.DrawRay with the same direction you are using for your raycast. That way you can see where the raycast is going.
Answer by LamborjimmyPOG · Mar 02 at 04:40 PM
@kylecat6330 I tried drawing the ray and it is going in the direction it is intended to. It looks like this and I also did enabled gizmos
Can you give us the code related to the raycast? It is hard to tell what is wrong without it.
Yes of course. I am using health script to apply damage to enemy RaycastHit hit; if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit)) { Debug.Log("Hit:" + hit.transform.name); HealthScript healthScript = hit.transform.GetComponent(); if (hit.transform.tag == "Enemy") { healthScript.ApplyDamage(damage); } }
What sort of colliders are on the enemies? What are their settings?
Your answer
