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

How do I fix my first person camera script?

Asked by 6 years ago

I'm making a custom first person camera script. As apposed to using roblox's so I can add smooth head bobbing, crouching etc. However, I'm bad at 3-D math so I'm stuck on how to make the camera turn with the mouse. What happens is the camera starts twisting and going out of control.

while not game.Players.LocalPlayer.Character do wait() end

local cam = workspace.CurrentCamera
cam.CameraType = "Scriptable"

local plrChar = game.Players.LocalPlayer.Character

local plrHead = plrChar:waitForChild("Head")
plrHead.LocalTransparencyModifier = 1

local CAMERA_MOVE_FACTOR = 3

local xAngle = 0
local yAngle = 0


inputService.InputChanged:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement then
        if input.Delta.x < 0 then
            xAngle = xAngle - CAMERA_MOVE_FACTOR
        elseif input.Delta.x > 0 then       
            xAngle = xAngle + CAMERA_MOVE_FACTOR
        end

        if input.Delta.y < 0 then
            yAngle = yAngle - CAMERA_MOVE_FACTOR
        elseif input.Delta.y > 0 then       
            yAngle = yAngle + CAMERA_MOVE_FACTOR        
        end
    end
end)

game:GetService("RunService").RenderStepped:connect(function()
    print(CFrame.Angles(math.rad(-yAngle),math.rad(-xAngle),0))
    cam.CFrame = CFrame.new(plrHead.CFrame.p) * CFrame.Angles(math.rad(-yAngle),math.rad(-xAngle),0)
end)
2
on 20, 22, 26 and 28, you might want to use multiply instead (eg xAngle * -CAMERA and xAngle *CAMERA) RubenKan 3615 — 6y
0
Okay Ill try it! gaberdell 71 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Line 8 is WaitForChild not waitForChild

0
Uh... Thanks I guess, but “WaitForChild” isn’t really answering my question gaberdell 71 — 6y
0
Plus capitalization doesn’t really matter there gaberdell 71 — 6y
Ad

Answer this question