local cameraAngleX = 0
local cameraAngleY = 0
CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
to set the angle of the camera
How would I make the camera face the brown part using only the vector of the HumanoidRootPart, the vector of the Brown Part and the cameraAngleX and cameraAngleY variables?
Context: When cameraAngleX is at 0, the camera faces the orange part
at 90, it faces the green part,
at 180, it faces the red part,
at 270, it faces the purple part
I do not want to use LookAt
I need the camera to change on both the X and Y axes
cameraAngleX denotes left and right
cameraAngleY denotes up and down
Since you are trying to get the Y axis of the angle, this will help you.
local function getAngle(touch, center) --touch is the position that you want it to look to.
return math.atan2(touch.X - center.X, touch.Z - center.Z) --and center is the center, of course.
end
EDIT
I mainly used this to make 2.5D or 2D.
2ND EDIT
This also returns a radian angle. So you don’t need to convert it to radian.
-- Formula for the angle between two vectors in 3D Space
local start = vector3.new(1, 2, 3)
local terminal = vector3.new(4, 5, 6)
angle = math.acos(((start.X*terminal.X)+(start.Y*terminal.Y)+(start.Z*terminal.Z))/(math.sqrt((start.X*start.X)+(start.Y*start.Y)+(start.Z*start.Z))*(math.sqrt((terminal.X*terminal.X)+(terminal.Y*terminal.Y)+(terminal.Z*terminal.Z)))))
You could simplify this with math.pow if you really wanted to. This answers your topic question. How you use it is up to you. The return is in radians I believe. To get it to degrees, you can do math.deg(angle) or angle*180/math.pi. Not sure if this answers your specific use-case.