#How do I make the FOV change when I hold the shift key?
59 messages · Page 1 of 1 (latest)
FieldOfVIew is a property of a camera object.
uis
localscript
workspace.currentcamera
i dont feel like writing a script rn
and if u want it smooth use tweenservice
you could use ContextActionService to change the field of view on leftshift press
or uis but that's a lil messier in my experience
nahhh we hate mobile
I dont even know how to write a script
true
I knew that part
go watch tutorials this is scripting help
u gotta know atleast know some basics
sure
my dumbass forgetting words in sentences
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)
lol
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
yes```lua
function StartFOV(key)
if key.KeyCode == Enum.KeyCode.Shift then
-- change the Fov
end
end
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
u dont need lerp
no u are since the system u have is kinda bad and weird
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
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
i can get my friend to give me a 2k script that updates fov smoothly but dont need it
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)
something like this achieves the same result in fewer lines of code and is usable on mobile
there's no one perfect solution
im being serious about the 2k line system