Raycast goes behind instead of in front?

Hello!
I’ve got this weird problem lately


So apparently, when i was testing out. Some of the bullets didnt hit the target. (like i was placing my mouse at the torso and it just goes backwards).
Code for the raycasts:

        local origin = player.Character.Head.Position
		local currentline = (hitpos - origin)
		local direction = currentline.Unit
		local distance = currentline.Magnitude * 1.5
		distance = 9999
		local ray = Ray.new(origin,direction * (distance + 3))
		local hit,Position,normal = workspace:FindPartOnRayWithIgnoreList(ray,{player.Character,game.Workspace.Barriers})

It looks fine. What is the issue??

Please help!

1 Like

what is thhe currentLine variable?

change the direction to be equal to -currentline.Unit

the unit direction points from the mouse hit to the character head
just reverse it by making it negative

2 Likes

It is the direction of the raycast (without length )

Most of the bullet goes backwards :(. It doesnt work

Oh nvm just add the head to the blacklist

1 Like

I already added player.Character to the blacklisted

add the gun model too, it can hit it self

The gunmodel is on the client side. Im not sure how to replicate it to the server side

Ok i figured out something.
https://i.gyazo.com/038766f8e3d5a425dc4f85a9d6013e72.mp4
The red part is where the raycast hitted. Im not pretty sure what it hitted but turns out some of them hit and it is quite nearly behind the player

Does the red part have CanQuery off?

Oh wait I figured it out!
The mouse.Hit.p is from the client side and will detect anything on server or client. Im pretty sure I forgot to add a targetfilter. So you must either add a target filter OR a raycast with ignorelist.