Its the first time I’m using :dot() and its giving me this error attempt to index number with 'Dot'. I’m trying to make a function that checks if the player has the same or similar orientation as the specific part, buuuut it seems I’m doing something wrong but I don’t know what, any suggestions???
whole code:
local function angleBetweenVectors(vec1, vec2)
return math.deg(math.acos(vec1:Dot(vec2) / (vec1.Magnitude * vec2.Magnitude)))
end
Yes, but where do you call the function ,like where do you do -
local function angleBetweenVectors(vec1, vec2)
return math.deg(math.acos(vec1:Dot(vec2) / (vec1.Magnitude * vec2.Magnitude)))
end
angleBetweenVectors(vecA,vecB)
Detector.Touched:Connect(function(hit)
local playerOrientation = player.Character.HumanoidRootPart.CFrame:ToOrientation()
local partOrientation = Detector.CFrame:ToOrientation()
local angleBetween = angleBetweenVectors(partOrientation, playerOrientation)
if angleBetween <= 30 then
local x0, y0, z0 = player.Character.HumanoidRootPart.CFrame:ToOrientation()
local playerOrientation = Vector3.new(x0, y0, z0)
local x1, y1, z1 = Detector.CFrame:ToOrientation()
local partOrientation = Vector3.new(x1, y1, z1)
local angleBetween = angleBetweenVectors(playerOrientation, partOrientation)
Edit:
Alternatively, you can just pass the ToOrientation into a Vector3.new() like this:
local playerOrientation = Vector3.new(player.Character.HumanoidRootPart.CFrame:ToOrientation())
local partOrientation = Vector3.new(Detector.CFrame:ToOrientation())
local angleBetween = angleBetweenVectors(playerOrientation, partOrientation)