How to determine if an object is rotated to another object

It so happened that I need to determine whether the player is turned to another player. I have read a lot about CFrame but didn’t understand how to do it. I will be glad if you tell me how to do it.
I want to note that I don’t need to determine whether the player is turned to another without rejections, but it is necessary that there be an error in which it would be determined whether the player is looking at the player.

Maybe these could help

1 Like
	local p1 = game.Workspace.Part
	local p2 = game.Workspace.Part2

	local theoreticaldirection = (p2.Position-p1.Position).Unit
local realdirection = p1.CFrame.LookVector
local dotproduct = theoreticaldirection:Dot(realdirection)
if dotproduct > 0.95 and dotproduct <1.05 then -- you can increase the error size here.
	print("yes")
end

1 Like

I made a working code:

-- Below there should be paths on the part of the players from which we will determine their rotation
local p1 = game.Workspace.Part -- Which player we will determine if he is looking at 2 player
local p2 = game.Workspace.Part2 -- Player2

local Facing = p1.CFrame.LookVector
local Vector = (p2.Position - p1.Position).unit

local Angle = math.acos(Facing:Dot(Vector))
local C = math.deg(Angle) -- Converting radians to degrees

if C > 100 and C < 180 then -- See photo
	print("Yes")
end

Also a picture with degrees:


Part rotation: 0, 0, 0