Physics.Raycast Not Working... Kinda
I have three gameobjects (at least that relate to this problem). There's a bullet, there's an enemy, and there's a boss. The bullet is fired from the player, and contains a simple script that simply updates its transform in FixedUpdate by x speed. It also has a box collider. The enemy doesn't have a box collider, and fires a ray out in Update. The ray code looks like this:
RaycastHit hit;
if(Physics.Raycast(transform.position, -Vector3.forward, out hit, 0.25f))
{
if(hit.transform.CompareTag("Bullet"))
{
//Do thing here.
}
}
The bullet and the enemy both exist on the same plane, I've used Debug.DrawRay to confirm that they line up perfectly and the bullet's box collider is pretty massive so I can't imagine that they're not hitting eachother. But, actually, they are - this part is perfectly fine and the two work as I expect them to.
The problem arises when I introduce the boss. The boss has exactly the same raycast script and yet doesn't work at all - every bullet simply flies right through it. I tried sending a Debug.Log and took out the tag check entirely but it never fired. So I know that it's not a tagging problem and that it's just not detecting the bullet at all.
This situation is so bare bones that I am quickly running out of things to try. I have been desperately attempting to find the difference between the enemy and the boss that could be causing this and I've come up completely empty. I realize that maybe what I've explained isn't enough to go on to give a concrete answer, but any suggestions would be of great help. Though I've said that there's only a single enemy and a single boss, there's actually multiple of each and the enemies all work while the bosses simply don't. The rest of their script functions fine, just not this. I've combed through each of their scripts trying to find something that might be overriding the raycast in some way but I've come up with nothing. So if anyone has any questions, suggestions, or can help in any way I'd really appreciate it.,
Your answer
Follow this Question
Related Questions
Raycast doesn't stay in one place 0 Answers
RayCast2D and RayDraw errors 0 Answers
How would I project a Gameobject onto the surface of another? 0 Answers
2D raycast not working 0 Answers
raycasting doesn't work 1 Answer