I'm trying to get the yaw rotation (on y-axis), expressed like in the picture.
If the camera's lookvector is the blue arrow, then the yaw rotation would be pi/2.
If it would be in the opposite way, -pi/2.
I already managed to write a script for this but only in relation to the character,
so if I would turn around the character and look straight, the yaw rotation would be falsely pi/2 instead of -pi/2.
#How can I get the yaw rotation?
1 messages · Page 1 of 1 (latest)
function getYawPitch()
--if input.KeyCode ~= Enum.KeyCode.H then return end
local localCamera = Camera.CFrame
local yAngle = math.atan2(localCamera.LookVector.X, localCamera.LookVector.Z)
if getYaw() > math.pi/2 then
yAngle = -yAngle
end
local yaw = math.pi/2 + yAngle
--local pitch = math.asin(localCamera.lookVector.Y) * (-1)
-- wrap the rotation to be within [0, pi)
yaw = (yaw % math.pi + math.pi) % math.pi
-- if player looks behind, subtract pi to let the rotation be within [0, -pi)
if getYaw() > math.pi/2 then
yaw -= math.pi
end
print("yaw:", yaw)
return yaw
end
I think you just negate the yaw variable before you return it
@reef olive but wouldn't this negate it when the camera's lookvector is the blue arrow?
then the rotations would be just swapped, but not made global in any sense
your goal is to make the yaw rotation relative to world space?
yeah, right now it is relative to the humanoid for some reason.
if the lookvector is at -pi/2, then the yaw should be -pi/2, even if i would rotate the character and look into this direction, it wouldn't suddenly become pi/2 again
Are you using CurrentCamera
yeah
I need to know what's inside getYaw() function
this was just to make the backwards angle correct
i basically want this rotation circle to apply to the world
Try to do :Dot(CFrame.identity.LookVector) this might relative to the world