- Home /
Raycast hits player when looking down
Hi,
I made a few weapons in my game that use raycasting, blah blah, particles and a bulletshole spawn where the raycast hits. But there's a problem that I can't seem to fix.
As you can see in the video linked below, every time I shoot down, a bullet hole appears where my camera is. (https://youtu.be/sUVtZm__afU) I've checked everything and made sure there were no colliders blocking the way, but it's still hitting the camera every time I look down.
Does anyone know what might be causing this?
Thanks
Try adding a debug call to print the name of the object hitted by the ray cast, so you know who is on the way. Assu$$anonymous$$g there is nothing on the way of your raycast, could it be that your script is adding a bullet hole even when the raycast doesn't hit anything?
Try adding something like this after your if
statement:
if(hit != null)
{
Debug.log("Raycast hitted " + hit.collider.gameObject.name);
}
It said it was hitting the play collider that I want to use for hit detection, so I'm going to have to find a way around that. But even when I disabled that collider, it would still do the same thing, except that it would now hit the ground, which is what I'm standing on. I really have no idea why it would put a bullet hole in the air if it's hitting the ground.
Thank you, that sounds like it might just work! I'll try it out soon
Answer by virgiliu · May 27, 2015 at 12:15 PM
Use a layer mask in the Raycast() so the ray only collides with a certain layer http://docs.unity3d.com/ScriptReference/Physics.Raycast.html