Because we are using unit vectors, |a| and |b| are both one. So the equation simplifies to
a · b = cos(θ)
Where a and b are vectors and theta is the angle.
Now in Roblox; suppose you have a vector aligned to the Z-axis
local vectorA = Vector3.zAxis
And you want to measure the angle between it and another vector, that other vector being the LookVector of a part
You would use the dot product to derive that angle between them
local vectorA = Vector3.zAxis
local vectorB = workspace.Part.CFrame.LookVector
local angle = vectorA:Dot(vectorB)
Remember that angle is actually the cosine of the actual angle, so you will have to remove the cosine by using its inverse function:
local angle = math.acos(vectorA:Dot(vectorB))
However, angle is measured in radians. If you want to convert it to degrees, you will need to use math.deg
local angle = math.deg(math.acos(vectorA:Dot(vectorB)))
Ok and how exactly is using CFrames “too expensive” for what you’re doing? Have you done proper benchmarks comparing things like CFrame.lookAt to alternatives, if you even have them?
I did benchmark
just purely using cframes resulted in %10 activity
while using Unit to get lookvector resulted in %6 activity
because how many times I need to calculate cframes it became too expensive.
You don’t have a method of deriving angles from LookVectors yet (which is why you’re here asking for help) so that benchmark you did is flawed since you don’t even have what you’re trying to test
Just because getting the LookVector of a part is faster than CFrames does not necessarily mean it’s going to be computationally better at calculating angles
Do not draw conclusions from incomplete data