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

[Still Need Help] Camera Rotation Not Working As Expected?

Asked by 9 years ago

So I have a quite long script (disregard the module) that basically has an overview of the character and can zoom in/out (which I removed for this post) and can rotate up and down, and all around the character.

The problem is when rotating the camera angle along the Y axis (in this case that would be spinning around the character) it glitches out and can do random circles and never just does a perfect circle around the character.

The set up and variables in this might not be very reader friendly but just try to get the general sense of it and see if you can figure it out. Also to test what I mean by the wacky camera go to my test place here

If this is too hard to read on this website, go to here

local lib = require(game.Workspace.CameraModule)
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local mouse = plr:GetMouse()
local minzoom = 0.42
local maxzoom = 2.15
local zoom = 1 --Zoom multiplier
local rotation = {}
    rotation["x"] = 0
    rotation["y"] = 0
    rotation["z"] = 0
local uis = game:GetService("UserInputService")
local xrotmax = 58
local xrotmin = -12

char:WaitForChild("Humanoid").WalkSpeed = 0 --Just a test

lib.SetCameraToScriptable()
set = function()
    local cf = CFrame.new(char.HumanoidRootPart.Position) * CFrame.Angles(rotation["x"],, rotation["y"], rotation["z"]) * CFrame.new(0, 15 * zoom, 9 * zoom)
    lib.PointAt(cf, char.Head.CFrame)
end
set()

delay(0, function()
    game:GetService("RunService").RenderStepped:connect(function()
        set()
    end)
end)

--Put zoom functions here

local looped = {}

uis.InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local key = string.sub(tostring(input.KeyCode), 14) --This is fourteen because it's originally an enum value and to get to the part as to what letter or key it is, it is fourteen letters in.
        if key == "W" or key == "A" or key == "S" or key == "D" then
            delay(0, function()
                local rot = ((key == "W" or key == "A") and math.rad(-2) or (key == "S" or key == "D") and math.rad(2))
                looped[key] = true
                local rottype = ((key == "W" or key == "S") and "x" or (key == "A" or key == "D") and "y")
                while looped[key] and wait() do
                    local rotdeg = math.deg(rotation[rottype] + rot)
                    if rottype == "x" and not (rotdeg <= xrotmax and rotdeg >= xrotmin) then
                        break
                    end
                    rotation[rottype] = rotation[rottype] + rot
                end
            end)
        end
    end
end)

uis.InputEnded:connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local key = string.sub(tostring(input.KeyCode), 14)
        if looped[key] then
            looped[key] = false
        end
    end
end)

Answer this question