How to figure out if something is behind?

I have 2 parts. I am trying to figure out a solution to figure out if Part B is behind Part A.

How could I take a target and a point and figure out if that point is facing behind target, I currently posses the weakest grasp of understanding of mathematics or CFrames e.g
Sorry for my briefness.

Maybe you should try RayCast

Try something like this:

``````local objectA
local objectB

if objectA.CFrame:ToObjectSpace(objectB.CFrame).Position.Z < 0 then
print("Object A is behind object B")
end
``````

Define a direction that’s “front”. Take a target with x position of 10. In this example 10 and greater is in front. Just check if the parts position is less than 10.

I was going to mark this as the solution, but after more playing around:

``````workspace.Part:GetPropertyChangedSignal("CFrame"):Connect(function()
print(workspace.Part.CFrame:ToObjectSpace(workspace.Target.CFrame).Position.Z)
end)
``````

Rotating object A caused some interesting results
https://gyazo.com/d6babdf77c1cbef7c53e67a23a697d29
If object a is rotated enough it would be considered behind object b even though it is clearly not (the motor is used to show what direction object b is facing)

Found my own solution, marking this as one encase anyone else has an issue. While my knowledge is limited, I am aware of how to find a point X studs infront of behind something. Simply figure out which one the enemy is closer too in order to figure out if they are behind or not.

Red = Attacker
Black = Target
Green = Points

``````local function IsBehind(Target,AttackerLocation)
local point1,point2 = (Target.CFrame + Target.CFrame.LookVector),(Target.CFrame + Target.CFrame.LookVector*-1)
local mag1,mag2 = (point1.Position-AttackerLocation).Magnitude,(point2.Position-AttackerLocation).Magnitude
return not (mag1 <= mag2)
end``````