Can't get angle of Right Vector and lookvector

Hi, I’m trying to get a angle of my part’s lookvector and right vector but it doesn’t seem to be right

local gizmo = require(script:WaitForChild('gizmo'))

local test = workspace.test

	game["Run Service"].Heartbeat:Connect(function()
		local a = test.CFrame.LookVector
		local b = test.CFrame.RightVector
		local cos = (a.X*b.X+a.Y*b.Y+a.Z*b.Z) /((math.sqrt(a.X*a.X+a.Y*a.Y+a.Z*a.Z)) * math.sqrt(b.X*b.X+b.Y*b.Y+b.Z*b.Z))
		local deg = math.acos(cos)

what it prints :
the formula:

This is the correct answer; the max an angle of two points can ever be is pi because they are in a circle. If you divide that answer by pi and multiply it by 180, you should get the correct answer.

local part = workspace.Part
local a = part.CFrame.LookVector
local b = part.CFrame.RightVector

Using math.acos and dot is the faster way of doing your equation (I’m not too good at explaining this type of stuff, so sorry).

why we have to divide pi? Uhh, I think it convert rad to deg

The vectors form a circle, try looking with the rotation tool, those are directly 1 stud in each direction.

so that’s called unit circle right?

Yes, that would be considered a unit circle.

thanks man after doin some research I got it

I commend you if you’re trying to learn to do this yourself, but if you weren’t aware Roblox does have functions to take care of this math already via LookVector:Dot(RightVector)

Also, you don’t need to use spawn here. Events run asynchronously to the rest of your code.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.