i want to achieve a smooth run, where instead of instantly running it has a slow start, but i need the animation to slowly accelerate/decelerate smoothly with it
i have tried various ways to get this to work but none have been successful
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
local Animator = Humanoid:WaitForChild("Animator")
-- Running Configuration
local MaxSpeed = 20 -- Maximum running speed
local AccelerationRate = 0.3 -- Speed increase per cycle
local DecelerationRate = 0.5 -- Speed decrease per cycle
local BaseSpeed = 17 -- Default walking speed
local BaseFOV = 65 -- Default FOV
local MaxFOV = 75 -- Maximum FOV at full speed
local AnimationSpeedMultiplier = 0.7 -- Multiplier for animation speed
-- Animation Setup
local RunAnimation = Instance.new("Animation")
RunAnimation.AnimationId = "rbxassetid://88455436394577" -- Replace with your running animation ID
local IdleAnimation = Instance.new("Animation")
IdleAnimation.AnimationId = "rbxassetid://507766388" -- Replace with your idle animation ID
local RunTrack = Animator:LoadAnimation(RunAnimation)
local IdleTrack = Animator:LoadAnimation(IdleAnimation)
-- State Variables
local IsRunning = false
local CurrentSpeed = BaseSpeed
local TargetFOV = BaseFOV
-- Function to adjust the FOV smoothly
local function AdjustFOV(targetFOV, duration)
local tween = TweenService:Create(Camera, TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {FieldOfView = targetFOV})
tween:Play()
end
-- Running logic (accelerates while movement exists)
local function StartRunning()
if IsRunning then return end -- Prevent re-entering running state
IsRunning = true
-- Stop idle animation if playing (with fade-out)
if IdleTrack.IsPlaying then
IdleTrack:Stop(0.5)
end
-- Start running animation
RunTrack:Play()
while IsRunning do
if Humanoid.MoveDirection.Magnitude > 0 then
-- Gradually increase speed
CurrentSpeed = math.min(CurrentSpeed + AccelerationRate, MaxSpeed)
Humanoid.WalkSpeed = CurrentSpeed
-- Adjust FOV based on speed
local speedRatio = (CurrentSpeed - BaseSpeed) / (MaxSpeed - BaseSpeed)
TargetFOV = BaseFOV + (MaxFOV - BaseFOV) * speedRatio
AdjustFOV(TargetFOV, 0.1)
-- Increase animation speed in proportion to movement speed
local adjustedSpeed = (CurrentSpeed / BaseSpeed) * AnimationSpeedMultiplier
RunTrack:AdjustSpeed(adjustedSpeed)
else
break
end
task.wait(0.1)
end
-- If movement stopped, begin deceleration
if IsRunning then
StopRunning()
end
end
-- StopRunning logic (gradually decelerates movement and transitions to idle)
local function StopRunning()
if not IsRunning then return end
IsRunning = false
-- Gradually decelerate speed down to BaseSpeed
while CurrentSpeed > BaseSpeed do
CurrentSpeed = math.max(CurrentSpeed - DecelerationRate, BaseSpeed)
Humanoid.WalkSpeed = CurrentSpeed
local speedRatio = (CurrentSpeed - BaseSpeed) / (MaxSpeed - BaseSpeed)
TargetFOV = BaseFOV + (MaxFOV - BaseFOV) * speedRatio
AdjustFOV(TargetFOV, 0.1)
-- Adjust animation speed to match deceleration
local adjustedSpeed = (CurrentSpeed / BaseSpeed) * AnimationSpeedMultiplier
RunTrack:AdjustSpeed(adjustedSpeed)
task.wait(0.1)
end
-- Smooth transition to idle animation over 0.2 seconds
RunTrack:AdjustWeight(0, 0.2) -- Fade out the run animation over 0.2 seconds
IdleTrack:AdjustWeight(0, 0.2) -- Fade in the idle animation over 0.2 seconds
-- Reset walk speed and FOV
Humanoid.WalkSpeed = BaseSpeed
AdjustFOV(BaseFOV, 0.5)
end
-- Monitor movement changes to start or stop running
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if Humanoid.MoveDirection.Magnitude > 0 then
StartRunning()
else
StopRunning()
end
end)
this script is pretty bad for what im trying to do, if it helps to understand, its similar to games like parkour reborns running mechanic