Hi, so I just built a sample wall for maps I might create, but I noticed a bug. Apparently, when the character is close to the wall, depending on your angle you can actually shoot through it.
I’m assuming you’re starting your ray at the tip of the barrel. If that barrel is inside another part and you cast a ray, that part that “should be counted” wont be counted since from my understanding, rays only impact outside faces.
You can solve this by shifting your origin of the ray backwards into the player’s shoulder (where the player’s collider starts) and projecting your ray from there. Make sure you include your player’s character into the ignorelist.
Make sure you are checking to see that there are no parts between the players head and the barrel with raycasting. This will also stop shooting around corners.
If you are starting the raycasting further back, you might run into problems longer down the line. I feel as if the way I suggested may be easier but please respond if you can refute that.
Maybe I could cast another ray from the player’s head, in the player’s looking direction to a very short distance to determine if the player is too close to an object, and if that’s true, don’t allow them to shoot.
I’d like to hear these problems if you can state them! I don’t really thing there’s much changed with pushing the origin back. It’s also much less expensive than firing another ray within the same frame.
Hey, some of the problems I was thinking of is when the player shoots around the corner and instead of not firing, fires into a corner. I have seen this in some games result in team kill, especially guns with high damage or DPS. Another reason is bugs and glitches down the line, what if they have their arm inside a wall sideways and they fire, the gun and their shoulder are both in the wall and like you said, raycasting cannot pick up inner faces so the gun would shoot normally.
Combined with shift locking this could still result in wall shooting.
Raycasting from the head to the barrel means that they cannot do this as the head is collidable.
Wouldn’t it just be fine to raycast from the HRP to the target instead then? You wont have to fire a second ray and since it’s inside a collidable it should function similar to how you stated it.