Is there any way to find the angle of the camera between a part?

It’d be something fully zoomed in.
For example, if the camera is turned all the way behind the part exactly, it’d print out 180.

To find the angle of the camera relative to a part, you can calculate the angle between the forward vector of the part and the direction from the part to the camera.

  • Part Forward Vector:
    • part.CFrame.LookVector gives the forward direction of the part.
  • Camera Forward Vector:
    • camera.CFrame.LookVector gives the forward direction of the camera.
  • Dot Product and Angle:
    • The dot product of the part’s forward vector and the negative of the camera’s forward vector is can be used to determine the angle between the part’s forward direction and the direction the camera is looking from the part.
    • math.acos can be used to convert the dot product result to an angle in radians, which is then converted to degrees by multiplying by (180 / math.pi).

You may need to mess around with the calculations.

local part = workspace.Part -- Replace with your part
local camera = workspace.CurrentCamera

-- Get the part's forward vector
local partForward = part.CFrame.LookVector

-- Get the camera's forward vector
local cameraForward = camera.CFrame.LookVector

-- Calculate the angle between the two vectors
local angle = math.acos(partForward:Dot(-cameraForward)) * (180 / math.pi)

-- Print the angle
print("Angle between camera and part:", angle)
3 Likes

Seems to work spot on, thanks!

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