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

?Controller not moving the camera

Asked by 6 years ago

So basically I have a game where the camera type is attach. I added controller support. But, since the camera type is Attach, it wont actually move the camera. Can someone fix that? Here is the script for controller support:

-- Make variables for services
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")

-- Make variables for player, character, and camera
local player = game.Players.LocalPlayer
while not player.Character do wait() end
local character = player.Character
local camera = game.Workspace.CurrentCamera

-- Update camera rotation every render frame
local currentAngle = 0
local deltaAngle = 0
runService.RenderStepped:connect(function()
    currentAngle = currentAngle + deltaAngle
    camera.CoordinateFrame = CFrame.new(character.Head.Position) 
                                        * CFrame.Angles(0, math.rad(currentAngle), 0)
                                        * CFrame.new(0, 0, 10)
end)

-- Check for change event in input. Used for thumbstick input as those are analog
userInputService.InputChanged:connect(function(input, processed)
    if input.UserInputType == Enum.UserInputType.Gamepad1 then
        -- Check left thumbstick and move character on change
        if input.KeyCode == Enum.KeyCode.Thumbstick1 then
            character.Humanoid:Move(Vector3.new(input.Position.X, 0, -input.Position.Y), true)
        end
        -- Check right thumbstick and change camera angle on change
        if input.KeyCode == Enum.KeyCode.Thumbstick2 then
            deltaAngle = input.Position.X * 5 --This is where i am having trouble. I didnt make this script, so I dont know how to change it. Help please?
        end
    end
end)

-- Check for user input ended events. Handles release of R1 and thumbsticks
userInputService.InputEnded:connect(function(input, processed)
    if input.UserInputType == Enum.UserInputType.Gamepad1 then
        -- Stop moving character if left thumbstick released
        if input.KeyCode == Enum.KeyCode.Thumbstick1 then
            character.Humanoid:Move(Vector3.new(0,0,0))
        end
        -- Stop moving camera if right thumbstick released
        if input.KeyCode == Enum.KeyCode.Thumbstick2 then
            deltaAngle = 0
        end
        -- Make character move at normal speed if R1 is released
        if input.KeyCode == Enum.KeyCode.ButtonR1 then
            character.Humanoid.WalkSpeed = 16
        end
    end
end)

-- Check for user input began events. Handles jumping and increasing speed
userInputService.InputBegan:connect(function(input, processed)
    if input.UserInputType == Enum.UserInputType.Gamepad1 then
        -- If A button is pressed then make the character jump
        if input.KeyCode == Enum.KeyCode.ButtonA then
            character.Humanoid.Jump = true
        end
    end

Answer this question