Raycasted bullets go through objects

  1. What do I want to achieve?
    I want the bullets to stop in place if it hits a part

  2. What is the issue?
    My raycasted bullets shoot through objects.
    Here’s a gif presentation of what’s happening: https://gyazo.com/1fe55e9de7733f5fd4e1f83e6db996a5

Any help at all would be greatly appreciated. Thank you for your time :slightly_smiling_face: :+1:

1 Like

Did you use a midpoint? because your bullet I saw was an exact length

Yeah I did, sorry I forgot to send the script lol

No problem! This is actually my first time being a member. I’ll do my best!

Here is the script for the gun:

Why don’t you make a part that first spawns by hitting by raycasting, after you got a endpos, you can make a midpoint from the origin with a endpos!

Can you explain this a bit more? I kinda understand your point but not entirely.

because you are using a range of shooting which is 50 and you divide by 2
and got a result in 25 then the range of the gun will be the same!
This is my solution

first you get a hit part

local hitpos = hit.Position

then you get a origin pos

local origin = originPosition
so now you need a magnitude
local magnitude = (origin - hitpos).Magnitude
now u get a distance of a origin and a hitpart
then you can get a midpoint by doing a origin + magnitude/2 (or your midpoint thing)

now the result should work!

try it!

I get an error that states “Unable to cast double to Vector3”. :confused:

It is because you blacklisted the building.

When you blacklist something the Raycast will ignore it and go straight through it.

I suggest removing the RaycastParameters completely unless you want the Raycast to be able to “pierce” objects. In that case put the objects u want the Raycast to go through into the table.

just noticed that magnitude IS not a vector3
but wait!
why dont we do another raycasting with a range of the magnitude we got instead
:thinking:

You set the bullet’s can collide to false. Set it to true.

Sure that it still wont work. because it have a anchored as true

What do you mean it has anchored to true? How is it going to affect the bullet’s can collide.

Because the problem is that the bullet’s can go through objects. Even you anchored the object
It will be lock in that position!

I think I know the issue here. The problem is that the mouse’s position will identify where the ray cast does cast. The mouse is a 2d object so you would think it’s shooting it at the dummy but in reality it’s past the wall so the ray cast will be casted past the wall.

i think i got it
local newdirection = (mousePos - barrelPosition).Unit * magnitude
please try it first!

1 Like