Help with vectors

im no math wizard
but i need to learn how to create a vector for this system
someone who is actually good at math, please help.

function GetNormalFromFace(part, normalId)
	return part.CFrame:VectorToWorldSpace(Vector3.FromNormalId(normalId))
end

function NormalToFace(normalVector, part)

	local TOLERANCE_VALUE = 1 - 0.001
	local allFaceNormalIds = {
		Enum.NormalId.Front,
		Enum.NormalId.Back,
		Enum.NormalId.Bottom,
		Enum.NormalId.Top,
		Enum.NormalId.Left,
		Enum.NormalId.Right
	}    

	for _, normalId in pairs( allFaceNormalIds ) do
		-- If the two vectors are almost parallel,
		if GetNormalFromFace(part, normalId):Dot(normalVector) > TOLERANCE_VALUE then
			return normalId -- We found it!
		end
	end
	
end

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, mousePos)

	local direction = (mousePos - script.Parent.Handle.Position).Unit
	local raycast = workspace:Raycast(script.Parent.Handle.Position, direction*3000, RaycastParams.new())
	
	if raycast.Instance then
		local vector -- right here
		
		local normalId = NormalToFace(vector, raycast.Instance)

		if normalId then print(normalId) end
	end
end)
2 Likes

What do you want from the vector? I have to assume from the code you want it to pick a face of the object the mouse is pointing at? If that’s the case you can just use your direction vector.

local vector = direction
2 Likes

Do you mean raycast.Position?ㅤㅤㅤㅤㅤㅤㅤㅤ

it works, just sometimes
it also has input lag