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)