What does CFrame.LookVector * [number] actually do?

I have a working Raycasting script but I want to know what the CFrame * 99 part is actually doing. I used it without the * 99 and it didnt work and it only works when multiplied by a number. Why is this? how does changing the number change the distance?

I’m not sure whether this is needed or not but here’s the script for good measure:

local torso = script.Parent:WaitForChild("Torso")



local function raycastfunc()
	local raycastResult = workspace:Raycast(torso.Position, torso.CFrame.LookVector * 99)
	print('casting...')
	if raycastResult then
	local hitPart = raycastResult.Instance
	if hitPart then
		print('ok')
	else
		print ('no')
	end
end
end


while wait(3) do
	raycastfunc()
	break
	end

Yep, you should visualize it yourself for better understanding.

Also if there is no result the endpoint is the same as originVector + directionVector

1 Like

Raycasting uses a directional vector which is a normal/unit vector.
These can be either something like: 1, 0, 0, -1, 1, 0, 0, etc.

In CFrames, a LookVector is where the CFrame is facing towards (if it’s facing up, it becomes 0,1,0)
If you multiply that LookVector you get something like for example 0,0, -30.2.

When it comes to raycasting, these are usually used to measure how long the raycast goes for. If your directional vector is 1 stud on the Z axis, it will raycast from the origin until it reaches the directional vector which in this case is 0, 0, 1. This means, it has only traveled one stud.

If we do something like :Raycast(root.Position, root.CFrame.LookVector * 50, params) (where root is a humanoidrootpart), it will cast about 50 studs from where the root is facing.

4 Likes

Thanks for the explanations, I understand the concept now.