As the title says, I want to achieve better gradual FOV increase when accelerating a car, as mine has a problem. I’ve looked on Youtube and DevForum, but I haven’t found anything that helps me.
This is the code I have so far, but it tweens every single frame, which is not very optimized.
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local VehicleSeat = script.Parent.Parent
local DefaultFOV = Camera.FieldOfView
local RenderStepped = RunService.RenderStepped:Connect(function()
local calculation = (Engine.Velocity.Magnitude / VehicleSeat.MaxSpeed)
TweenService:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {
FieldOfView = DefaultFOV * math.clamp((calculation * (0.25 / 1)) + 1, 1, 1.25)
}):Play()
end)
VehicleSeat.Changed:Connect(function()
TweenService:Create(Camera, TweenInfo.new(0.25, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {
FieldOfView = DefaultFOV
}):Play()
end)
Also, it seems that even after I stop accelerating it seems that there is a certain delay before stopping the Tween, but I don’t know how to fix it.
Edit: when he leaves the vehicle, the FOV doesn’t go down to default.