Hey everybody! I’m currently in need of help since my math isn’t the best, but I’ve been trying to implement bullet penetration into my weapon system, but I’ve had no luck. Would anyone be able to share their own experience, and potentially teach me how it should be done? I use very simple raycasting. There’s no physics involved, just point A and point B. Thank you very much for any help!
Well the real question is, where and how are you trying to accomplish this? Raycasting has 3 necessary rays: the
RayDirection. In your case, you do not know the
RayDestination because It’s a bullet. If you want to accomplish a bullet system I would advise the
RayOrigin to be the Gun’s PrimaryPart or a small part at the end of the gun. The
RayDestination should be the player’s character’s HumanoidRootPart. If you want to find the closest player’s HumanoidRootPart, I could probably DM you the code since It’s pretty long and I don’t want to spoonfeed
I have all that completed. There’s also no bullet, it’s just instantaneous travel from origin to destination. Whatever gets caught in the middle between origin and destination is the obstacle I want to be able to apply bullet penetration to.
What I need help learning, is when it hits an object, how do I detect the thickness of that object.
you would use a raycast to see where it would hit…
I already have that… I need help with the calculation…
so you already have where the bullet would hit?
ooh wait you need to know the thickness of the object it hits?
Yes. I need help determining whether or not to pen the wall. Which means I need to be able to detect the thkckness of the object it hit. I have no idea how to do that. This is what I’m trying to learn.
you would just use math to find the distance between where the bullet enters and where the bullet exists right? Do you already know how to find these points?
To find the distance between 2 things it’s
local Distance = (Position1 - Position2).magnitude
Have you checked these other posts on the same topic?
How do I detect where the bullet exits the part? It’s a raycast, so there’s no physical properties of the cast to reference when it exits the object in question.
This was incredibly helpful! Thank you very much for sharing these. I didn’t even think about casting backwards.
What I did was added the part to the ignore list and raycast again. This probably works for bullet penetration as well, but casting backwards also works. I haven’t done any benchmarking, but I think raycasting with the new ignore list is more efficient since you’re using the same RaycastParams and don’t have to do math to figure out the new origin.