How to raycast directly infront of the head

I know I asked this before but now I have a different problem. I am trying to raycast from the head of the client to see where the player is looking towards. Heres my code:

while wait(1) do
			local MyRayCast = Ray.new(Head.CFrame.p, Head.CFrame.LookVector * 100)
			local part = workspace:FindPartOnRay(MyRayCast)
			if part.Name == "NPCWall2" then
				print("Yes")
			elseif part.Name == "Wall2" then
				print("Yessir")
			end
		end

Now, this all works perfectly fine but the problem I’m having is that one of the parts is too far away therefore the raycast doesnt reach it. How can I extend the raycast from the head in my code?
aka. I need to change up the Head.CFrame.LookVector * 100

Can’t you just multiply it by 1000 instead?

local MyRayCast = Ray.new(Head.CFrame.p, Head.CFrame.LookVector * 1000)

Videos and pictures could help.

I will try that thank you. (that was what I was stuck on since I dont really know what LookVector is haha)

LookVector is the direction the character is facing. I believe they’re usually numbers between -1 and 1.

1 Like

The LookVector should be a unit vector, meaning it always has a magnitude of 1 :slight_smile:

2 Likes

I’m glad you know all the semantics of predefined methods and variables haha

1 Like

Hey, I tried multiplying it by 1000 but it didn’t seem to change the ray’s length. any idea?

I did something similar to this, but it was coming from the chest.

local hrp = player.Character.HumanoidRootPart
local ray = Ray.new(hrp.Position, hrp.CFrame.lookVector * 10)
local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {hrp.Parent, tool})

This ray only went like 5 studs in front of the character but by change it from * 10 to say * 500 it would go much further.

1 Like

Dont worry. I just placed a non collision and transparent part which is closer to the user. Thanks for the help though