What do you want to achieve? Keep it simple and clear!
Find out camera’s CFrame.Angles.Y to fill in the “currentY” variable
Convert / Calculate camera’s lookVector.Y to CFrame.Angles.Y (I don’
t know if this would work)
I want to set the currentY to camera’s CFrame.Angles.Y but i have no idea how to find it. So i used lookVector.Y to calculate the CFrame.Angles.Y (Code below)
What is the issue? Include screenshots / videos if possible!
I found out that value between lookVector.Y and CFrame.Angles.Y aren’t same
-- calculation to find rotation X
local currentX = math.atan2(-camera.CFrame.LookVector.X, -camera.CFrame.LookVector.Z) / math.pi * 180
-- Need help here to find rotation Y
local currentY = camera.CFrame.LookVector.Y * 80
-- Set current X and Y for the variables below
local angleX, targetAngleX = currentX, currentX
local angleY, targetAngleY = currentY, currentY
local function onUpdateCamera(actionName, inputState, inputObject)
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local sensitivity = 0.4
local delta = Vector2.new(inputObject.Delta.X * sensitivity, inputObject.Delta.Y * sensitivity)
local x = targetAngleX - delta.X
local y = targetAngleY - delta.Y
targetAngleX = x
targetAngleY = math.clamp(y, -80, 80)
angleX = angleX + (targetAngleX - angleX) * 0.35
angleY = angleY + (targetAngleY - angleY) * 0.35
camera.CFrame = CFrame.new(camera.CFrame.p)
* CFrame.Angles(0, math.rad(angleX), 0)
* CFrame.Angles(math.rad(angleY), 0, 0)
local lookVectorY = camera.CFrame.LookVector.Y * 80
print(angleY, lookVectorY)
end
LookVector.Y between X and Y axis should be 0.5 but it doesn’t
In my mind,
LookVector.Y = 0; CFrame.Angles.Y = 0
LookVector.Y = 0.5; CFrame.Angles.Y = 45
LookVector.Y = 1; CFrame.Angles.Y = 90
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I searched up in forum and doesn’t see any question related to my problem.
I tried to do the calculation between lookVector and CFrame.Angles and doesn’t achieve my goal.
Addition
Some of the reply i might not understand because the calculation confused me or i wrongy used lookVector to calculate CFrame.Angles.
If theres any coding mistake please correct me to improve my coding skill. Thanks
Thanks for your reply but i have no idea how can i use CFrame:ToEulerAnglesXYZ ( ) to find the camera CFrame because the wiki page just shown the format. Can you give some example and explanation? If can, I’ll be very grateful.
Thanks alot @ee0w I learnt that from your valuable reply. Is there any way more accurate than this method or i used the CFrame:ToEulerAnglesXYZ ( ) wrongy?
Just one thing to point out; .Changed will fire when any property changes, if you want it so only when their CFrame then use :GetPropertyChangedSignal("CFrame")
Thanks @ee0w and @return_end1’s remind. After i calculated the multiply value for CFrame:ToEulerAnglesXYZ ( ) and is it good using 57.29578607161983 instead of 57.3?
Finished product
local currentX = math.atan2(-camera.CFrame.LookVector.X, -camera.CFrame.LookVector.Z) / math.pi * 180
local currentY = camera.CFrame:ToEulerAnglesYXZ() * 57.29578607161983
local angleX, targetAngleX = currentX, currentX
local angleY, targetAngleY = currentY, currentY
local function onUpdateCamera(actionName, inputState, inputObject)
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local sensitivity = 0.4
local delta = Vector2.new(inputObject.Delta.X * sensitivity, inputObject.Delta.Y * sensitivity)
local x = targetAngleX - delta.X
local y = targetAngleY - delta.Y
targetAngleX = x
targetAngleY = math.clamp(y, -80, 80)
angleX = angleX + (targetAngleX - angleX) * 0.35
angleY = angleY + (targetAngleY - angleY) * 0.35
camera.CFrame = CFrame.new(camera.CFrame.p)
* CFrame.Angles(0, math.rad(angleX), 0)
* CFrame.Angles(math.rad(angleY), 0, 0)
local currentAngleY = camera.CFrame:ToEulerAnglesYXZ() * 57.29578607161983
print(angleY, currentAngleY)
end
contextActionService:BindAction("UpdateCamera", onUpdateCamera, false, Enum.UserInputType.MouseMovement)