Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I check if my gun is colliding through a wall?

Asked by 8 years ago
Edited 8 years ago

I'm currently making an fps and I am stumped on how to proceed with preventing shooting through walls (sticking your gun through a wall then firing).

Currently I'm considering giving the gun a hitbox and preventing it from firing if the hitbox hits a wall (edit: INSIDE a wall), however, I have no idea how to do this - I've experimented with touched and I don't know how to properly use it to do this. Any help is greatly appreciated! Thanks.

0
You could try casting a ray from the tip of the gun to your player's head, if it can't hit, it would mean they're shooting through a wall Perci1 4988 — 8y
0
I don't mean bullet collision detection, I mean actual weapon detection - the weapon itself has a hitbox and can't fire if it is stuck through a wall to prevent shooting through walls, where the tip would be on the other side of a wall. coolyoshipower 42 — 8y
1
yeah that's what i'm saying, you could try casting a a ray from the tip of the gun to your head. if there's something in the way, they're probably trying to shoot through a wall. Perci1 4988 — 8y
0
Ah, I see. Sorry, I misread your previous answer. I'll try this now. coolyoshipower 42 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

I was afraid of someone doing this while making my gun for a murder game,so i decided to make a ray that comes from the head of the player,instead of the gun.

01--Local Script
02 
03tool=script.Parent
04clickEvent=tool.ClickEvent
05 
06tool.Equipped:connect(function(mouse)
07    mouse.Button1Down:connect(function()
08        clickEvent:FireServer(mouse.Hit.p)
09    end)
10end)
11 
12--Server script
13 
14tool=script.Parent
15clickEvent=tool.ClickEvent
View all 26 lines...

Hope this helped ya :D

Ad

Answer this question