How do i detect the dotproduct if something is behind it

Hi, so… does dotproduct has anything like back angle? i use LookVector for my dotproduct so, i can’t change it to rightvector, but where is the back angle though?

:script border:

if dot > (BackAngle) then
script.Parent.Throttle = -1
script.Parent.Throttle = 1
:script border:

Are you checking if a part’s position is behind another part by using dot product? Or are you trying to tell if dot product is 0.7 or something

im just checking if a part positions is behind the other part by just using dotproduct

Yeah you can use dot product and check the angle degree between the part1’s lookvector and part1’s lookvector toward part2

local BackAngle = 270 --If part2 is 270 degrees away from part1's lookvector then its at the back

local Part1 = --your part1
local Part2 = --your part2

local P1Look = Part1.CFrame.LookVector
local P1LookP2 = (Part2.Position - Part1.Position).Unit

local angle = math.deg(math.acos(P1Look:Dot(P1LookP2) / (P1Look.Magnitude / P1LookP2.Magnitude)))

if angle > BackAngle then
   print("Object exceeds back angle")
   print("Object is ok")

i will test it now


didn’t work

The dot product is negative for two vectors facing “away-ish” from each other.

A.Unit:Dot(B.Unit) is equal to

  • 1 when they face the same direction
  • 0.5 when they’re 60 degrees apart
  • 0 when they’re 90 degrees apart
  • -0.5 when they’re 120 degrees apart
  • -1 when they’re 180 degrees apart

Did it only print the second print even if the part is behind? Could you try placing the part2 behind part1 and print the angle

i did and it all printed ‘‘not back’’

I forgot that getting the angle from dot product only goes up to 180, so try making the back angle something like 150

nvm i fixed it.

i just added a another dotproduct