Always getting the camera to rotate in a desired direction?

Hi, so I’m making a simple camera system similar to that of Five Nights at Freddy’s 4, where you can look behind yourself towards the bed, then back to the default view of the room, from right-to-left.

The issue I’m having is that sometimes when I use TweenService, it’ll actually rotate left-to-right since I think it determines that distance is shorter than if it were to rotate right-to-left. (I want the camera to always rotate clockwise first, then counter-clockwise as you look back to the room, so it’s like a look over your right shoulder.)

I remember having this problem before, but I wasn’t sure what the workaround was for this.

I can clarify more if needed, thank you!

1 Like

I mean I did a totally different system where I labelled the positions of the different areas you look at and used CFrame.lookAt() instead

This is early on https://gyazo.com/9ea78aa7bb723e953a1de9dd8b633e39
But as you can see it worked fine for me, heck heres the alpha game here

1 Like

Thanks,

but how could that work for my case though? I’d think the same problem would occur, like even if I tweened the camera’s CFrame to that, it’d make sense for it to still rotate the wrong way as it sees that rotating counter-clockwise is the shorter distance rather than rotating clockwise.

Couldn’t you just bind a small angle offset to render step? Then when it’s at your desired angle, do the offset but negative?

2 Likes

Since my movements were as you say “fixed” I think it will still work,

and as @7z99 said I don’t know how you’re doing your angles but you can set angles to over 360 meaning it can go to 380 instead of using a hacky solution of 20

or negative like he said too

2 Likes

I’m actually really stumped on this, it shouldn’t be this difficult but it’s confusing me because it keeps rotating the other way, despite how I go about actually updating the target angle.

You know your target angles, correct?

Try something like this:

local targLeft = 180 -- left target
local targRight = -180 -- right target

local runService = game:GetService('RunService')
local camera = workspace.CurrentCamera
local left, right
function left()
    camera.CFrame *= CFrame.Angles(0,math.rad(0.05),0)
    local x,y,z = camera.CFrame:ToEulerAnglesXYZ()
    if math.floor(math.deg(y)) == targLeft then
        runService:UnbindFromRenderStep('left')
        runService:BindToRenderStep('right', Enum.RenderPriority.Camera + 1, right)
    end
end 
function right()
    camera.CFrame *= CFrame.Angles(0,math.rad(-0.05),0) -- ensure you do negative on the y axis, or positive on this and negative on the above
    local x,y,z = camera.CFrame:ToEulerAnglesXYZ()
    if math.floor(math.deg(y)) == targRight then
        runService:UnbindFromRenderStep('right')
        runService:BindToRenderStep('left', Enum.RenderPriority.Camera + 1, left)
    end
end

runService:BindToRenderStep('left', Enum.RenderPriority.Camera + 1, left)
1 Like