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

FPS camera is stuck in a specific position?

Asked by 7 years ago

Is there anything wrong with this script? It's a script for a FPS but it won't allow the camera to move, it makes it stuck in a particular position.

wait(.5)
_G.RecoilY = 0
_G.RecoilX = 0
_G.MouseSensitivity = 1
_G.PrimarySensitivity = 1
_G.SecondarySensitivity = 1
_G.TertiarySensitivity = 1

_G.Target = nil
_G.Zoomed = false
--game.StarterGui:SetCoreGuiEnabled("Health", false)
local RunService = game:GetService("RunService")
local RenderStepped = RunService.RenderStepped
local UserInputService = game:GetService("UserInputService")
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
UserInputService.MouseIconEnabled = false
--
local Player = game.Players.LocalPlayer
local myChar = Player.Character
Player.CameraMode = "LockFirstPerson"
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
Camera.CameraType = "Custom"
Camera.FieldOfView = 70
Camera.CameraType = "Custom"
Camera:ClearAllChildren()
repeat wait() until Player.Character ~= nil
repeat wait() until Player.Character:FindFirstChild("Head") ~= nil
_G.Target = Player.Character.Head
--[[stuff = Player.Character:GetChildren()
for i = 1, #stuff do
    thing = stuff[i]
    if thing:IsA("Hat") then
        thing:remove()
    end
end]]
xangle = 0
yangle = 0

UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
Camera.CameraType = "Scriptable"
UserInputService.InputChanged:connect(function(inputObject)
    local inputObject = inputObject
    if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
        local XChange, YChange = inputObject.Delta.X, inputObject.Delta.Y
        if _G.Zoomed == true then
            xangle = xangle + YChange*0.005*_G.MouseSensitivity
            yangle = yangle + XChange*0.005*_G.MouseSensitivity
        else
            xangle = xangle + YChange*0.005
            yangle = yangle + XChange*0.005
        end
        newxangle = xangle
        if -xangle+_G.RecoilX > math.rad(89) then
            xangle = -math.rad(89)
            _G.RecoilX = 0
        Camera.CoordinateFrame = CFrame.new(_G.Target.Position)  --Start at the position of the part
                           * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle
                           * CFrame.new(0, 0, 0)  *CFrame.Angles(-xangle,0,0)
        elseif -xangle+_G.RecoilX < -math.rad(89) then
            xangle = math.rad(89)
            _G.RecoilX = 0
        Camera.CoordinateFrame = CFrame.new(_G.Target.Position)  --Start at the position of the part
                           * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle
                           * CFrame.new(0, 0, 0)  *CFrame.Angles(-xangle,0,0)
        else
        Camera.CoordinateFrame = CFrame.new(_G.Target.Position)  --Start at the position of the part
                           * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle
                           * CFrame.new(0, 0, 0)  *CFrame.Angles(-xangle+_G.RecoilX,0,0)
        end


        local MDir = Camera.CoordinateFrame.lookVector--mouse.UnitRay.Direction.unit
        local RotTarget = Vector3.new(MDir.x,0,MDir.z)
        local cfYaw = CFrame.new(myChar.HumanoidRootPart.Position,myChar.HumanoidRootPart.Position + RotTarget)
        myChar.HumanoidRootPart.CFrame = cfYaw  
    end
end)

RenderStepped:connect(function()
        if -xangle+_G.RecoilX > math.rad(89) then
            xangle = -math.rad(89)
            _G.RecoilX = 0
        Camera.CoordinateFrame = CFrame.new(_G.Target.Position)  --Start at the position of the part
                           * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle
                           * CFrame.new(0, 0, 0)  *CFrame.Angles(-xangle,0,0)
        elseif -xangle+_G.RecoilX < -math.rad(89) then
            xangle = math.rad(89)
            _G.RecoilX = 0
        Camera.CoordinateFrame = CFrame.new(_G.Target.Position)  --Start at the position of the part
                           * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle
                           * CFrame.new(0, 0, 0)  *CFrame.Angles(-xangle,0,0)
        else
        Camera.CoordinateFrame = CFrame.new(_G.Target.Position)  --Start at the position of the part
                           * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle
                           * CFrame.new(0, 0, 0)  *CFrame.Angles(-xangle+_G.RecoilX,0,0)
        end
    local MDir = Camera.CoordinateFrame.lookVector--mouse.UnitRay.Direction.unit
    local RotTarget = Vector3.new(MDir.x,0,MDir.z)
    local cfYaw = CFrame.new(myChar.HumanoidRootPart.Position,myChar.HumanoidRootPart.Position + RotTarget)
    myChar.HumanoidRootPart.CFrame = cfYaw
end)
0
I think I´m kind of failing to understand exactly what you want this script to accomplish. When I read the title I thought FPS camera but that wouldnt need.. any of this. That would simply just be game:GetService('Players').LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson harryisbeast 70 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

This should be a solution, can't really figure out what the script you provided is trying to achieve.

local Players = game.Players.LocalPlayer

Players.CameraMode = "LockFirstPerson"

Make sure this goes into a local script, preferably in game.StarterPlayer.StarterPlayerScripts

Hoped this helped.

-- The only one, Astrallife.

0
Also, the script looks like it should belong in the gun (Or tool), as a local script. LevelHeadedLogic 13 — 7y
Ad

Answer this question