Ray Cast Not Working Consistently

I was just about getting started with ray casts when I encountered this problem

(the white box is the hitbox)
(another picture taken from the exact same position just waited a little)

If you look at the output it changes but I did not even move a inch. If someone could tell me why it would be a big help! And also a side note do ray casts have a range? If so can I make it infinite?
edit: I forgot to mention but here is my script!

local player = game.Players.LocalPlayer
local character = player.Character
local head = character:WaitForChild("Head")

local raycastparams = RaycastParams.new()

raycastparams.FilterType = Enum.RaycastFilterType.Include
raycastparams.FilterDescendantsInstances = {game.Workspace.scp096.Hitbox}

while true do
	local ray = game.Workspace:Raycast(head.Position, head.CFrame.LookVector * 100, raycastparams)
	if ray and ray.Instance then

(its a local script in starter character scripts)

Forgot to mention again but if anyone knows how to make it so that the ray cast ignores the part if its from behind please do answer it!

1 Like

use raycastParams, use blacklist (excluded) and ray skip the selected parts,
{blacklistedPart1, workspace --[[dont try it btw]]}

1 Like

What I mean is that I have one part and I only want the ray cast to work if the ray cast hits it from its front face. If it hits it from any other it should not work. Can you tell me how to do that if you know?

1 Like

you’re doing a scp-096 demonstration, just use mousehit position and check the distance of hit and our characters humanoidrootpart

1 Like

you dont need to use raycast for check 096’s face, just use Mouse

1 Like

Well I still have not decided whether I want it to be 3rd person or 1st person. If I made it first person then your method would definitely work and in my opinion developing a game in 1st person is much easier. But I do think that the 3rd person feel is just good and I am most likely going to make the game in 3rd person thus I need to use RAY CAST because that would mean that if they put their mouse on it in 3rd person it would activate even if they were not looking at the scp and same thing even if they were they can put there mouse off the scp.

Im Pretty Sure Your Aware Of All Of This But Im Putting It In Anyway

Thanks For The Reply!

edit: the only reason i took the screen shot in first person was because it was easier Sorry For The Misunderstanding

1 Like

I Changed My Mind And Now I’m Doing First Person But Since Im Doing First Person This Really Helps Me Thanks!

1 Like

Also Is It Better To Use A Click Detector Or A Mouse Detector Script?

Thanks For The Reply!

I remember a vector3 called DotPoint probably this help you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.