Advertisement
61k_NightRider

Roblox Realistic Footsteps Sounds

Jun 13th, 2025
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.40 KB | Gaming | 0 0
  1. -- // Animate script // --
  2.  
  3. local Debris = game:GetService("Debris")
  4. local Players = game:GetService("Players")
  5. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  6. local RunService = game:GetService("RunService")
  7.  
  8. local character = script.Parent
  9. local humanoid = character:WaitForChild("Humanoid")
  10. local root = character:WaitForChild("HumanoidRootPart")
  11. local animator = humanoid:WaitForChild("Animator")
  12. local footprintFolder = ReplicatedStorage:WaitForChild("Footprints")
  13.  
  14. local footsteps = require(script:WaitForChild("Footsteps"))
  15. local lastFootstepSound = nil
  16. local animTracks = {}
  17. local transitionTime = 0.2
  18. local jumpAnimTime = 0
  19. local holdingTool = false
  20.  
  21. local function StopAllAnimations(ignoreName)
  22.     for i, animTrack in pairs(animator:GetPlayingAnimationTracks()) do
  23.         if animTrack.Name == ignoreName
  24.             or (ignoreName == "Run" and animTrack.Name == "Walk")
  25.             or (holdingTool and animTrack.Name == "Tool") then
  26.             continue
  27.         end
  28.         animTrack:Stop(transitionTime)
  29.     end
  30. end
  31.  
  32. local function AdjustAnimation(name, speed, weight)
  33.     animTracks[name]:AdjustSpeed(speed)
  34.     animTracks[name]:AdjustWeight(weight)
  35. end
  36.  
  37. local function PlayAnimation(name, speed, weight)
  38.     animTracks[name]:Play(transitionTime)
  39.     AdjustAnimation(name, speed, weight)
  40.     StopAllAnimations(name)
  41. end
  42.  
  43. local function Running(speed)
  44.     if speed > 0.5 then
  45.  
  46.         local relativeSpeed = speed / 16
  47.         local runAnimWeight, walkAnimWeight = 0.001, 0.001
  48.  
  49.         if relativeSpeed < 0.5 then
  50.             -- Walking speed
  51.             walkAnimWeight = 1 
  52.         elseif relativeSpeed < 0.9 then
  53.             -- Blend run and walk
  54.             local fadeInRun = (relativeSpeed - 0.5)/(1 - relativeSpeed)
  55.             walkAnimWeight = 1 - fadeInRun
  56.             runAnimWeight  = fadeInRun
  57.             relativeSpeed = 1
  58.         else
  59.             -- Simply run
  60.             runAnimWeight = 1
  61.         end
  62.  
  63.         if animTracks["Run"].IsPlaying then
  64.             if speed > 0.5 then
  65.                 AdjustAnimation("Walk", 0.8, walkAnimWeight)
  66.                 AdjustAnimation("Run", 0.8, runAnimWeight) 
  67.             end
  68.         else
  69.             PlayAnimation("Walk", 0.8, walkAnimWeight)
  70.             PlayAnimation("Run", 0.8, runAnimWeight)
  71.         end
  72.     else
  73.         PlayAnimation("Idle")
  74.     end
  75. end
  76.  
  77. local function Jumping()
  78.     jumpAnimTime = 0.31
  79.     PlayAnimation("Jump")
  80. end
  81.  
  82. local function Falling()
  83.     if (jumpAnimTime <= 0) then
  84.         PlayAnimation("Fall")
  85.     end
  86. end
  87.  
  88. local function Climbing(speed)
  89.     if speed == 0 then
  90.         if not animTracks["Run"].IsPlaying then
  91.             AdjustAnimation("Climb", 0, 1)
  92.         end
  93.     else
  94.         local relativeSpeed = speed / 5
  95.         if animTracks["Climb"].IsPlaying then
  96.             AdjustAnimation("Climb", relativeSpeed, 1)
  97.         else
  98.             PlayAnimation("Climb", relativeSpeed)
  99.         end
  100.  
  101.     end
  102. end
  103.  
  104. local function Swimming(speed)
  105.     if speed > 1 then
  106.         local relativeSpeed = speed / 10
  107.         if animTracks["Swim"].IsPlaying then
  108.             AdjustAnimation("Swim", relativeSpeed, 1)
  109.         else
  110.             PlayAnimation("Swim", relativeSpeed)
  111.         end
  112.     elseif not animTracks["SwimIdle"].IsPlaying then
  113.         PlayAnimation("SwimIdle", 1)
  114.     end
  115. end
  116.  
  117. local function PlayFootstepSound(foot, material)
  118.     if not foot then return end
  119.  
  120.     local sounds = footsteps.sounds[material]
  121.     if not sounds then return end
  122.  
  123.     local random = Random.new()
  124.     local soundId = sounds[random:NextInteger(1, #sounds)]
  125.  
  126.     if soundId and soundId ~= lastFootstepSound then
  127.         lastFootstepSound = soundId
  128.         local sfx = Instance.new("Sound")
  129.         sfx.SoundId = soundId
  130.         sfx.RollOffMaxDistance = 100
  131.         sfx.RollOffMinDistance = 10
  132.         sfx.Volume = footsteps.volume[material] or 0.5
  133.         sfx.Parent = foot
  134.         sfx:Play()
  135.         task.spawn(function()
  136.             sfx.Ended:Wait()
  137.             sfx:Destroy()
  138.         end)
  139.     else
  140.         PlayFootstepSound(foot, material)
  141.     end
  142. end
  143.  
  144. local function OnFootStep(side)
  145.     local foot = character:FindFirstChild(side.."Foot")
  146.     local floorMaterial = humanoid.FloorMaterial
  147.     local material = footsteps.materialMap[floorMaterial]
  148.  
  149.     PlayFootstepSound(foot, material)
  150.  
  151.     if material then
  152.         local footprint = footprintFolder:FindFirstChild(material)
  153.         if footprint then
  154.             warn('mat found')
  155.             footprint = footprint:Clone()
  156.             footprint:PivotTo(foot.CFrame * CFrame.new(0, -footprint.PrimaryPart.Size.Y, 0))
  157.             footprint.Parent = workspace
  158.             Debris:AddItem(footprint, footsteps.decay[material] or 3)
  159.         end
  160.     end
  161. end
  162.  
  163. function LoadAnimations()
  164.    
  165.     local animationIDs = {
  166.         Climb = "rbxassetid://10921257536",
  167.         Fall = "rbxassetid://10921262864",
  168.         Idle = "rbxassetid://10921258489",
  169.         Jump = "rbxassetid://10921263860",
  170.         Run = "rbxassetid://95928028565568", -- My custom anim: 11096667011
  171.         Walk = "rbxassetid://95928028565568",
  172.         Sit = "rbxassetid://10921269718",
  173.         Swim = "rbxassetid://10921264784",
  174.         SwimIdle = "rbxassetid://10921265698",
  175.         Tool = "rbxassetid://507768375"
  176.     }
  177.  
  178.     local defaultAnimateScript = character:WaitForChild("Animate", 3)
  179.     if defaultAnimateScript then
  180.         defaultAnimateScript:Destroy()
  181.     end
  182.  
  183.     for name, id in pairs(animationIDs) do
  184.         local animation = Instance.new("Animation")
  185.         animation.AnimationId = id
  186.         local track = animator:LoadAnimation(animation)
  187.         animTracks[name] = track
  188.         animTracks[name].Name = name
  189.         if name == "Idle" then
  190.             animTracks[name].Priority = Enum.AnimationPriority.Idle
  191.         elseif name == "Run" or name == "Walk" or name == "Climb" then
  192.             animTracks[name].Priority = Enum.AnimationPriority.Movement
  193.         elseif name == "Tool" or name == "Jump" --[[or name == "Fall"]] then
  194.             animTracks[name].Priority = Enum.AnimationPriority.Action
  195.         end
  196.  
  197.     end
  198.  
  199.     animTracks["Idle"]:Play()
  200.  
  201.     humanoid.Running:Connect(Running)
  202.     humanoid.Jumping:Connect(Jumping)
  203.     humanoid.FallingDown:Connect(Jumping)
  204.     humanoid.FreeFalling:Connect(Falling)
  205.     humanoid.Climbing:Connect(Climbing)
  206.     humanoid.Swimming:Connect(Swimming)
  207.  
  208.     -- Custom animation with keyframe marker required for this to work
  209.     if animationIDs.Run ~= "rbxassetid://10921261968" then
  210.         local oldRunSound = root:WaitForChild("Running")
  211.         oldRunSound:Destroy()
  212.         animTracks["Run"]:GetMarkerReachedSignal("Footstep"):Connect(OnFootStep)
  213.     end
  214. end
  215.  
  216. LoadAnimations()
  217.  
  218. RunService.Heartbeat:Connect(function(deltaTime)
  219.     if (jumpAnimTime > 0) then
  220.         jumpAnimTime = jumpAnimTime - deltaTime
  221.     end
  222.  
  223.     local tool = character:FindFirstChildOfClass("Tool")
  224.     if tool and tool:FindFirstChild("Handle") then
  225.         holdingTool = true
  226.         if not animTracks["Tool"].IsPlaying then
  227.             animTracks["Tool"]:Play(transitionTime)
  228.         end
  229.     else
  230.         holdingTool = false
  231.         animTracks["Tool"]:Stop(transitionTime)
  232.     end
  233. end)
  234.  
  235.  
  236.  
  237. -- // Footsteps script -- //
  238.  
  239. local footsteps = {}
  240. footsteps.sounds = {
  241.     ["Carpet"] = {
  242.         "rbxassetid://9126748130",
  243.         "rbxassetid://9126747861",
  244.         "rbxassetid://9126747720",
  245.         "rbxassetid://9126747529",
  246.     },
  247.  
  248.     ["Concrete"] = {
  249.         "rbxassetid://9126746167",
  250.         "rbxassetid://9126746098",
  251.         "rbxassetid://9126745995",
  252.         "rbxassetid://9126745877",
  253.     },
  254.  
  255.     ["Dirt"] = {
  256.         "rbxassetid://9126744390",
  257.         "rbxassetid://9126744718",
  258.         "rbxassetid://9126744263",
  259.         "rbxassetid://9126744157",
  260.     },
  261.  
  262.     ["Glass"] = {
  263.         "rbxassetid://9126742971",
  264.         "rbxassetid://9126742461",
  265.         "rbxassetid://9126742875",
  266.         "rbxassetid://9126742786",
  267.     },
  268.  
  269.     ["Grass"] = {
  270.         "rbxassetid://9126742396",
  271.         "rbxassetid://9126741427",
  272.         "rbxassetid://9126742333",
  273.         "rbxassetid://9126742215",
  274.     },
  275.  
  276.     ["Metal"] = {
  277.         "rbxassetid://9126736470",
  278.         "rbxassetid://9126734921",
  279.         "rbxassetid://9126736274",
  280.         "rbxassetid://9126736354",
  281.     },
  282.  
  283.     ["Sand"] = {
  284.         "rbxassetid://9126733118",
  285.         "rbxassetid://9126733408",
  286.         "rbxassetid://9126733225",
  287.     },
  288.  
  289.     ["Snow"] = {
  290.         "rbxassetid://9126732128", -- 11718221253
  291.         "rbxassetid://9126731099", -- 11718221627
  292.         "rbxassetid://9126732016", -- 11708681479
  293.     },
  294.  
  295.     ["Tile"] = {
  296.         "rbxassetid://9126730713",
  297.         "rbxassetid://9126730782",
  298.         "rbxassetid://9126731037",
  299.         "rbxassetid://9126730980",
  300.     },
  301.     ["Wood"] = {
  302.         "rbxassetid://9126931624",
  303.         "rbxassetid://9126931515",
  304.         "rbxassetid://9126931417",
  305.         "rbxassetid://9126931322",
  306.     }
  307. }
  308.  
  309. footsteps.volume = {
  310.     ["Tile"] = 1,
  311.     ["Grass"] = 1,
  312.     ["Dirt"] = 1,
  313.     ["Wood"] = 1,
  314.     ["Snow"] = 1,  
  315. }
  316.  
  317. footsteps.decay = {
  318.     ["Sand"] = 2,
  319.     ["Snow"] = 5,
  320. }
  321.  
  322. footsteps.materialMap = {
  323.     [Enum.Material.Fabric] =        "Carpet",
  324.  
  325.     [Enum.Material.Slate] =         "Concrete",
  326.     [Enum.Material.Concrete] =      "Concrete",
  327.     [Enum.Material.Brick] =         "Concrete",
  328.     [Enum.Material.Cobblestone] =   "Concrete",
  329.     [Enum.Material.Sandstone] =     "Concrete",
  330.     [Enum.Material.Rock] =          "Concrete",
  331.     [Enum.Material.Basalt] =        "Concrete",
  332.     [Enum.Material.CrackedLava] =   "Concrete",
  333.     [Enum.Material.Asphalt] =       "Concrete",
  334.     [Enum.Material.Limestone] =     "Concrete",
  335.     [Enum.Material.Pavement] =      "Concrete",
  336.     [Enum.Material.Pebble] =        "Concrete",
  337.  
  338.     [Enum.Material.Ground] =        "Dirt",
  339.     [Enum.Material.Mud] =           "Dirt",
  340.  
  341.     [Enum.Material.Grass] =         "Grass",
  342.     [Enum.Material.LeafyGrass] =    "Grass",
  343.  
  344.     [Enum.Material.Sand] =          "Sand",
  345.     [Enum.Material.Salt] =          "Sand",
  346.  
  347.     [Enum.Material.Snow] =          "Snow",
  348.     [Enum.Material.Glacier] =       "Snow",
  349.  
  350.     [Enum.Material.Plastic] =       "Tile",
  351.     [Enum.Material.Marble] =        "Tile",
  352.     [Enum.Material.Granite] =       "Tile",
  353.     [Enum.Material.SmoothPlastic] = "Tile",
  354.  
  355.     [Enum.Material.Wood] =          "Wood",
  356.     [Enum.Material.WoodPlanks] =    "Wood",
  357.  
  358.     [Enum.Material.CorrodedMetal] = "Metal",
  359.     [Enum.Material.DiamondPlate] =  "Metal",
  360.     [Enum.Material.Metal] =         "Metal",
  361.     [Enum.Material.Foil] =          "Metal",
  362.  
  363.     [Enum.Material.Ice] =           "Glass",
  364.     [Enum.Material.Glacier] =       "Glass",
  365.     [Enum.Material.Glass] =         "Glass",
  366.     [Enum.Material.Neon] =          "Glass",
  367.     [Enum.Material.ForceField] =    "Glass",
  368. }
  369.  
  370. return footsteps
  371.  
  372.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement