#How do I make the FOV change when I hold the shift key?

59 messages · Page 1 of 1 (latest)

formal spear
#

I have searched for quite some time now.

strong galleon
formal spear
#

So how do I do that in a script?

#

(I am very very new btw, also dumb)

vapid meteor
#

uis

#

localscript

#

workspace.currentcamera

#

i dont feel like writing a script rn

#

and if u want it smooth use tweenservice

crude yoke
#

you could use ContextActionService to change the field of view on leftshift press

#

or uis but that's a lil messier in my experience

vapid meteor
#

nahhh we hate mobile

formal spear
#

I dont even know how to write a script

formal spear
crude yoke
#

uis means userinputservice

#

if you didnt know

formal spear
#

I knew that part

vapid meteor
#

u gotta know atleast know some basics

formal spear
#

sure

vapid meteor
#

my dumbass forgetting words in sentences

formal spear
#

just needed to get some direction

#

ty

crude yoke
#
local CAS = game:GetService("ContextActionService")
local ACTION_SPRINT = "Sprint"
local currentlySprinting = false

local function handleAction(actionName,inputState,inputObject)
  if actionName == ACTION_SPRINT then
    currentlySprinting = (inputState == Enum.UserInputState.Begin)
  end
end

task.spawn(function()
  while true do
    if currentlySprinting then
      workspace.CurrentCamera.FieldOfView = 90
    else
      workspace.CurrentCamera.FieldOfView = 70
    end
    task.wait()
  end
end)

CAS:BindAction(ACTION_SPRINT,handleAction,true,Enum.KeyCode.LeftShift)
#

if it errors that's because i wrote it all in discord

#

in short, sets a boolean variable to the state of whether or not leftshift is pressed, and changes the fov based on that

#

if you want it to lerp you can, like change smoothly, you can change the task.spawn while loop to something like this instead

#
local lerp = 7

task.spawn(function()
  while true do
    if currentlySprinting then
      workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + ((90-workspace.CurrentCamera.FieldOfView)/lerp)
    else
      workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + ((70-workspace.CurrentCamera.FieldOfView)/lerp)
    end
    task.wait()
  end
end)
polar steppe
#

lol

crude yoke
#

enum.key?

#

look at the script i sent above

#

the one you replied to is just a patch to make the fov lerp

#

the script i sent originally changes fov based on leftshift being pressed

#

i.e., what he asked for

polar steppe
# crude yoke enum.key?

yes```lua
function StartFOV(key)
if key.KeyCode == Enum.KeyCode.Shift then
-- change the Fov
end
end

crude yoke
#
local UIS = game:GetService("UserInputService")
local lerp = 7
game:GetService("RunService").RenderStepped:Connect(function()
    local pressing = false
    for _,v in pairs(UIS:GetKeysPressed()) do
        if v.KeyCode == Enum.KeyCode.LeftShift then
            pressing = true
        end
    end
    if pressing then
        workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + ((120-workspace.CurrentCamera.FieldOfView)/lerp)
    else
        workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + ((50-workspace.CurrentCamera.FieldOfView)/lerp)
    end
end)
#

much more compact script using UIS

polar steppe
#

u dont need lerp

crude yoke
#

it is an option

#

in case they want it

#

damn

#

picky ass

polar steppe
#

no u are since the system u have is kinda bad and weird

crude yoke
#

enlighten me

#

i'd love to learn how to improve my code

#

what's wrong with it

polar steppe
# crude yoke i'd love to learn how to improve my code

now this is much better since u dont need so many complex things for a FOV change on pressing LeftShift```lua
local User = game:GetService('UserInputService')

function getFov()
local FOV = workspace.CurrentCamera
return FOV
end

function ChangeFOV(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
local Fov = getFov()
Fov.FieldOfView = 90
end
end

function ReturnFOV(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
local Fov = getFov()
Fov.FieldOfView = 70
end
end

User.InputBegan:Connect(ChangeFOV)
User.InputEnded:Connect(ReturnFOV)``` @formal spear

#

i can make one more advance than urs but dont need to have things that need lerp and loops to update FOV

crude yoke
#

it's more digestible yeah

#

i can see that much

#

i don't really see how anything is wrong with mine, we just came up with different solutions

#

lerp isnt necessary and there are other solutions to capturing user input than using UIS:GetKeysPressed() like how you showed

#

but imo there's nothing necessarily wrong with mine

polar steppe
#

i can get my friend to give me a 2k script that updates fov smoothly but dont need it

crude yoke
#
local CAS = game:GetService("ContextActionService")

local function handleAction(actionName,inputState,inputObject)
  if actionName == "Sprint" then
    if inputState == Enum.UserInputState.Begin then
      workspace.CurrentCamera.FieldOfView = 90
    else
      workspace.CurrentCamera.FieldOfView = 70
    end
  end
end

CAS:BindAction("Sprint",handleAction,true,Enum.KeyCode.LeftShift)
crude yoke
#

there's no one perfect solution

polar steppe
#

im being serious about the 2k line system