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

How Do I Change The Shoulder Camera Script In The "Auto Rifle" Model By Roblox Continuation 3?

Asked by 3 years ago
Edited 3 years ago

Check my original post "How Do I Change The Shoulder Camera Scripts In The "Auto Rifle" Model By Roblox To Change Plr Camera?" and check my second post "How Do I Change The Shoulder Camera Scripts In The "Auto Rifle" Model By Roblox Continuation? and check my third post "How Do I Change The Shoulder Camera Scripts In The "Auto Rifle" Model By Roblox Continuation 2?" (I'm sorry for how long these series of questions are, please answer if you can.)

--Continuation
function ShoulderCamera:handleTouchToolFiring()
    if self.touchObj then
        if self.lastTapEndTime then -- and not (self.zoomState and self.hasScope) then
            local touchTime = tick() - self.lastTapEndTime
            if touchTime < self.touchDelayTime and self.currentTool and self.touchPanAccumulator.Magnitude < 0.5 and not self.firingTool and not self.applyingTouchPan then
                self.firingTool = true
                self.currentTool:Activate()
            end
        end
    else
        if self.currentTool and self.firingTool then
            self.currentTool:Deactivate()
        end
        self.firingTool = false
    end
end

function ShoulderCamera:isTouchPositionForCamera(pos)
    if LocalPlayer then
        local guiObjects = LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(pos.X, pos.Y)
        for _, guiObject in ipairs(guiObjects) do
            if guiObject.Name == "DynamicThumbstickFrame" then
                return false
            end
        end
        return true
    end
    return false
end

function ShoulderCamera:onInputBegan(inputObj, wasProcessed)
    if self.touchObj then
        self.touchObj = nil
        wasProcessed = false
    end

    if inputObj.KeyCode == Enum.KeyCode.Thumbstick2 then
        self.gamepadPan = Vector2.new(inputObj.Position.X, inputObj.Position.Y)
    elseif inputObj.KeyCode == Enum.KeyCode.Thumbstick1 then
        self.movementPan = Vector2.new(inputObj.Position.X, inputObj.Position.Y)
    elseif inputObj.UserInputType == Enum.UserInputType.Touch then
        local touchStartPos = Vector2.new(inputObj.Position.X, inputObj.Position.Y)
        if not wasProcessed and self:isTouchPositionForCamera(touchStartPos) and not self.touchObj then
            self.touchObj = inputObj
            self.touchStartTime = tick()
            self.eventConnections.touchChanged = inputObj.Changed:Connect(function(prop)
                if prop == "Position" then
                    local touchTime = tick() - self.touchStartTime

                    local newTouchPos = Vector2.new(inputObj.Position.X, inputObj.Position.Y)
                    local delta = (newTouchPos - touchStartPos) * self.currentTouchSensitivity
                    local yawInput = -delta.X
                    local pitchInput = -delta.Y
                    if self.touchPanAccumulator.Magnitude > 0.01 and touchTime > self.touchDelayTime then
                        if not self.applyingTouchPan then
                            self.applyingTouchPan = true
                            self.touchPanAccumulator = Vector2.new(0, 0)
                        end
                    end
                    self:applyInput(yawInput, pitchInput)
                    self.touchPanAccumulator = self.touchPanAccumulator + Vector2.new(yawInput, pitchInput)
                    touchStartPos = newTouchPos
                end
            end)
        end
    end
end

function ShoulderCamera:onInputChanged(inputObj, wasProcessed)
    if inputObj.UserInputType == Enum.UserInputType.MouseMovement then
        local yawInput = -inputObj.Delta.X * self.currentMouseRadsPerPixel.X
        local pitchInput = -inputObj.Delta.Y * self.currentMouseRadsPerPixel.Y

        self:applyInput(yawInput, pitchInput)
    elseif inputObj.KeyCode == Enum.KeyCode.Thumbstick2 then
        self.gamepadPan = Vector2.new(inputObj.Position.X, inputObj.Position.Y)
    elseif inputObj.KeyCode == Enum.KeyCode.Thumbstick1 then
        self.movementPan = Vector2.new(inputObj.Position.X, inputObj.Position.Y)
    end
end

function ShoulderCamera:onInputEnded(inputObj, wasProcessed)
    if inputObj.KeyCode == Enum.KeyCode.Thumbstick2 then
        self.gamepadPan = Vector2.new(0, 0)
    elseif inputObj.KeyCode == Enum.KeyCode.Thumbstick1 then
        self.movementPan = Vector2.new(0, 0)
    elseif inputObj.UserInputType == Enum.UserInputType.Touch then
        if self.touchObj == inputObj then
            if self.eventConnections and self.eventConnections.touchChanged then
                self.eventConnections.touchChanged:Disconnect()
                self.eventConnections.touchChanged = nil
            end

            local touchTime = tick() - self.touchStartTime
            if self.currentTool and self.firingTool then
                self.currentTool:Deactivate()
            elseif self.zoomState and self.hasScope and touchTime < self.touchDelayTime and not self.applyingTouchPan then
                self.currentTool:Activate() -- this makes sure to shoot the sniper with a single tap when it is zoomed in
                self.currentTool:Deactivate()
            end
            self.firingTool = false

            self.touchPanAccumulator = Vector2.new(0, 0)
            if touchTime < self.touchDelayTime and not self.applyingTouchPan then
                self.lastTapEndTime = tick()
            else
                self.lastTapEndTime = nil
            end
            self.applyingTouchPan = false

            self.gamepadPan = Vector2.new(0, 0)
            self.touchObj = nil
        end
    end
end

return ShoulderCamera

1 answer

Log in to vote
0
Answered by 3 years ago

The Script I tried to use but didn't work to change the CFrame of the player camera.

(Script):

wait(5)

local GUI = script.Parent.Frame

local cam = workspace.CurrentCamera

local UIS = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local target = game.Workspace.TpBlock

cam.CFrame = workspace.FocusPart.CFrame --The Part That I tried to make the player camera's CFrame = to the part but it didn't work because the shoulder camera script in the "Auto Rifle" Model By Roblox kept the camera at a single CFrame

UIS.InputBegan:Connect(function(keyCode)
    if keyCode.keyCode == Enum.KeyCode.F then
        if GUI.Visible == true then
            GUI.Visible = false
            player.Character.LowerTorso.CFrame = target.CFrame * CFrame.new(0, 3, 0)
        end
    end
end)
Ad

Answer this question