Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Custom Camera Script Help, Camera Pointing Problems?

Asked by 7 years ago
Edited 7 years ago

This is an intsy-bitsy problem, but it has grown quite annoying. This is my FPS-3rd Person script, which allows a smoother camera when zoomed in(instead of the griddy feeling when you increase FOV in FirstPerson). However, when I switch from 3rd person to first person, the camera doesn't face where it was facing in 3rd person but instead, is facing towards where it was last looking when it was in first person.

Say my camera points at Point A in first person. I zoom out and move my camera towards Point B. When I zoom back in to first person, instead of still looking at Point B I'm looking at Point A again! Is that a good example? It's annoying when you are shooting at an enemy and zoom in only to be forced to look behind you!

input.InputChanged:connect(function(inputObject) -- this is what calculates where I should be looking at in first person. for some reason, it stops calculating this when I zoom out. I can't figure out a way to keep this function running because I need the inputObject variable.

    if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
        local delta = Vector2.new(inputObject.Delta.x/Sensitivity, inputObject.Delta.y/Sensitivity) * Smoothness
        local X = TargetAngleX - delta.y 
        TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X 
        TargetAngleY = (TargetAngleY - delta.x) %360 

        CamPos = CamPos + (TargetCamPos - CamPos) * 0.28 
        AngleX = AngleX + (TargetAngleX - AngleX) * 0.35 
        local dist = TargetAngleY - AngleY 
        dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist 
        AngleY = (AngleY + dist *0.35) %360
    end 

end)

script.Parent:WaitForChild("IsFirstPerson").Changed:connect(function()
    if not running and script.Parent.IsFirstPerson.Value == true then
        running = true
        runService:BindToRenderStep("RunFirstPerson", Enum.RenderPriority.First.Value + 1, function()
            if running then
                updatechar()

                workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
                workspace.CurrentCamera.CoordinateFrame = CFrame.new(head.Position) 
                * CFrame.Angles(0,math.rad(AngleY),0) 
                * CFrame.Angles(math.rad(AngleX),0,0)
                * CFrame.new(0,0,0) -- offset

                humanoidpart.CFrame = CFrame.new(humanoidpart.Position) * CFrame.Angles(0,math.rad(AngleY),0)
                else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
            end
            game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter

        end)
    end
end)

Answer this question