local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local Players = game:GetService("Players") local DEBUG = false local CONFIG = { GroundSpeed = 20, AirWishSpeed = 5.0, AirAccelerate = 1000, GroundAccelerate = 100, Friction = 5.5, JumpHeight = 5.5, } local UP = Vector3.new(0, 1, 0) local ZERO = Vector3.new(0, 0, 0) local HALF_PI = math.pi / 2 local ROT90 = CFrame.Angles(0, HALF_PI, 0) local RAY_OFFSETS = { Vector3.new( 0.0, 0, 0.0), Vector3.new(-0.8, 0, 0.0), Vector3.new( 0.8, 0, 0.0), Vector3.new( 0.0, 0, 0.8), Vector3.new( 0.0, 0, -0.8), } pcall(function() RunService:UnbindFromRenderStep("bhopUpdateLoop") end) local player local character local collider local camera local input local mobileJumpHeld = false local playerGrounded local jumping local moveInputSum local dt = 1/60 local cameraYaw local cameraLook local currentAccelDir = ZERO local movementPosition local movementVelocity local gravityForce local playerTorsoToGround local movementStickDistance local jumpVelocity local movementPositionForce local movementVelocityForce local rayYLength local movementPositionD local movementPositionP local movementVelocityP local gravity local standOffset local freefallEnabled = true local animateScript local humanoidRef local wasGrounded = nil local raycastParams = RaycastParams.new() raycastParams.FilterType = Enum.RaycastFilterType.Exclude raycastParams.RespectCanCollide = false local function dbg(...) if DEBUG then print("[bhop]", ...) end end local SPAWN_SOUND_ID = "rbxassetid://106589456758677" local SPAWN_SOUND_VOLUME = 2 local SPAWN_SOUND_MAX_DIST = 200 local LAND_SOUND_IDS = { "rbxassetid://7338942417", "rbxassetid://7338942345", "rbxassetid://7338942259", "rbxassetid://7338942180", "rbxassetid://7338942417", } local LAND_VOLUME = 2 local MIN_INTERVAL = 0.05 -- Предзагружаем звуки один раз, чтобы они воспроизводились мгновенно task.spawn(function() pcall(function() game:GetService("ContentProvider"):PreloadAsync(LAND_SOUND_IDS) end) end) local function getTorsoPart(char) if not char then return nil end return char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso") or char:FindFirstChild("HumanoidRootPart") end local function getFootParts(char, allowFallback) local parts = {} if not char then return parts end local function addByNames(names) for _, name in ipairs(names) do local p = char:FindFirstChild(name) if p and p:IsA("BasePart") then table.insert(parts, p) end end end addByNames({"LeftFoot", "RightFoot"}) if #parts == 0 then addByNames({"Left Leg", "Right Leg"}) end if #parts == 0 then addByNames({"LeftLowerLeg", "RightLowerLeg"}) end if #parts == 0 and allowFallback ~= false then local hrp = char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("Torso") if hrp and hrp:IsA("BasePart") then table.insert(parts, hrp) end end return parts end local function playSpawnSound() local torso local t0 = os.clock() while os.clock() - t0 < 10 do torso = getTorsoPart(character) if torso and torso.Parent then break end task.wait(0.05) end if not torso then return end local s = Instance.new("Sound") s.Name = "BhopSpawnSound" s.SoundId = SPAWN_SOUND_ID s.Volume = SPAWN_SOUND_VOLUME s.RollOffMode = Enum.RollOffMode.InverseTapered s.RollOffMaxDistance = SPAWN_SOUND_MAX_DIST s.RollOffMinDistance = 10 s.Parent = torso s:Play() if s.Ended then s.Ended:Connect(function() s:Destroy() end) end task.delay(15, function() if s and s.Parent then s:Destroy() end end) end local landPool = {} local poolCharacter = nil local lastLandPlay = 0 local function destroyLandPool() for _, s in ipairs(landPool) do if s then s:Destroy() end end landPool = {} poolCharacter = nil end local function buildLandPool() destroyLandPool() if not character or not character.Parent then return end local feet = getFootParts(character) if #feet == 0 then return end poolCharacter = character for i, id in ipairs(LAND_SOUND_IDS) do local foot = feet[((i - 1) % #feet) + 1] local s = Instance.new("Sound") s.Name = "BhopLandSound" s.SoundId = id s.Volume = LAND_VOLUME s.RollOffMode = Enum.RollOffMode.InverseTapered s.RollOffMaxDistance = 200 s.RollOffMinDistance = 10 s.Parent = foot table.insert(landPool, s) end end local function ensureLandPool() -- Пул жёстко привязан к текущему персонажу: -- после смерти/респавна он всегда пересобирается на новые части if poolCharacter ~= character or #landPool == 0 then buildLandPool() if #landPool == 0 then return end end for _, s in ipairs(landPool) do if not s or not s.Parent then buildLandPool() break end end end local function playLandSound() local now = os.clock() if now - lastLandPlay < MIN_INTERVAL then return end lastLandPlay = now ensureLandPool() if #landPool == 0 then return end local s = landPool[math.random(1, #landPool)] if not s or not s.Parent then buildLandPool() if #landPool == 0 then return end s = landPool[math.random(1, #landPool)] end if s and s.Parent then s:Play() end end local LEG_PART_NAMES = { "Left Leg", "Right Leg", "LeftLeg", "RightLeg", "LeftFoot", "RightFoot", "LeftLowerLeg", "RightLowerLeg", "LeftUpperLeg", "RightUpperLeg", } local function resolveRootPart(char) return char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso") or char.PrimaryPart end local function protectAnimate() if not character then return end animateScript = animateScript or character:FindFirstChild("Animate") if animateScript and animateScript.Disabled then animateScript.Disabled = false end end local function waitForRootPart(char, timeout) local part = resolveRootPart(char) if part then return part end local t0 = os.clock() while os.clock() - t0 < (timeout or 10) do part = resolveRootPart(char) if part then return part end task.wait(0.1) end return nil end local function computeTorsoToGround() if not character then return nil end local rootPart = resolveRootPart(character) if not rootPart then return nil end local rootY = rootPart.Position.Y local lowest = nil for _, name in ipairs(LEG_PART_NAMES) do local p = character:FindFirstChild(name) if p and p:IsA("BasePart") then local bottom = p.Position.Y - p.Size.Y / 2 if bottom < rootY and (lowest == nil or bottom < lowest) then lowest = bottom end end end if lowest == nil then for _, p in ipairs(character:GetDescendants()) do if p:IsA("BasePart") and p ~= rootPart then local bottom = p.Position.Y - p.Size.Y / 2 if bottom < rootY and (lowest == nil or bottom < lowest) then lowest = bottom end end end end if lowest == nil then return nil end return math.clamp(rootY - lowest, 1, 10) end local function getCharacterMass() local asm = collider and collider.AssemblyMass if asm and asm > 0 then return asm end local mass = 0 if character then for _, p in ipairs(character:GetDescendants()) do if p:IsA("BasePart") then mass = mass + p:GetMass() end end end return mass end local function hookMobileJumpButton() local pg = player:FindFirstChild("PlayerGui") or player:WaitForChild("PlayerGui", 15) if not pg then return end local touchGui = pg:FindFirstChild("TouchGui") or pg:WaitForChild("TouchGui", 60) if not touchGui then return end local frame = touchGui:WaitForChild("TouchControlFrame", 15) if not frame then return end local btn = frame:WaitForChild("JumpButton", 15) if not btn then return end if not btn.InputBegan or not btn.InputEnded then return end btn.InputBegan:Connect(function(inp) if inp.UserInputType == Enum.UserInputType.Touch or inp.UserInputType == Enum.UserInputType.MouseButton1 then mobileJumpHeld = true end end) btn.InputEnded:Connect(function(inp) if inp.UserInputType == Enum.UserInputType.Touch or inp.UserInputType == Enum.UserInputType.MouseButton1 then mobileJumpHeld = false end end) end local function init(Player, Camera, Input) player = Player character = player.Character if not character then return false end local rootPart = waitForRootPart(character) if not rootPart then return false end collider = rootPart camera = Camera input = Input humanoidRef = character:FindFirstChildOfClass("Humanoid") playerGrounded = false moveInputSum = { ["forward"] = 0, ["side"] = 0 } raycastParams.FilterDescendantsInstances = { character, camera } standOffset = 0 playerTorsoToGround = (computeTorsoToGround() or 3) + standOffset movementStickDistance = 0.5 movementPositionForce = 400000 movementVelocityForce = 300000 rayYLength = playerTorsoToGround + movementStickDistance movementPositionD = 500 movementPositionP = 14000 movementVelocityP = 1500 gravity = 0.6 jumpVelocity = math.sqrt(2 * gravity * workspace.Gravity * CONFIG.JumpHeight) if humanoidRef then humanoidRef.PlatformStand = false pcall(function() humanoidRef.UseJumpPower = true end) humanoidRef.JumpPower = jumpVelocity end task.spawn(hookMobileJumpButton) animateScript = character:FindFirstChild("Animate") if animateScript then if animateScript.Disabled then animateScript.Disabled = false end local sig = animateScript:GetPropertyChangedSignal("Disabled") if sig then sig:Connect(function() if animateScript.Disabled then animateScript.Disabled = false end end) end end return true end local function initBodyMovers() movementPosition = Instance.new("BodyPosition", collider) movementPosition.Name = "movementPosition" movementPosition.D = movementPositionD movementPosition.P = movementPositionP movementPosition.maxForce = ZERO movementPosition.position = ZERO movementVelocity = Instance.new("BodyVelocity", collider) movementVelocity.Name = "movementVelocity" movementVelocity.P = movementVelocityP movementVelocity.maxForce = ZERO movementVelocity.velocity = ZERO gravityForce = Instance.new("BodyForce", collider) gravityForce.Name = "gravityForce" gravityForce.force = Vector3.new(0, (1 - gravity) * workspace.Gravity, 0) * getCharacterMass() end local function updateMoveInputSum() local fwd = (input["W"] and 1 or 0) - (input["S"] and 1 or 0) local sid = (input["A"] and 1 or 0) - (input["D"] and 1 or 0) if fwd == 0 and sid == 0 and humanoidRef then local md = humanoidRef.MoveDirection if md.Magnitude > 0.01 then local fx, fz = cameraLook.X, cameraLook.Z local mag = math.sqrt(fx*fx + fz*fz) if mag > 0.01 then fx, fz = fx / mag, fz / mag else fx, fz = 0, -1 end fwd = md.X * fx + md.Z * fz sid = md.X * fz - md.Z * fx end end moveInputSum["forward"] = fwd moveInputSum["side"] = sid end local function computeAccelDir() local f = moveInputSum["forward"] local s = moveInputSum["side"] if f == 0 and s == 0 then return ZERO end local accelForward = cameraLook * f local accelSide = (cameraYaw * ROT90).lookVector * s return (accelForward + accelSide).Unit end local function getYaw() local camCF = camera.CFrame local y = camCF.lookVector:Dot(UP) if y > 1 then y = 1 elseif y < -1 then y = -1 end local pitch = HALF_PI - math.acos(y) return camCF * CFrame.Angles(-pitch, 0, 0) end local function setCharacterRotation() local pos = collider.Position local look = camera.CFrame.lookVector collider.CFrame = CFrame.new(pos, Vector3.new(pos.X + look.X, pos.Y, pos.Z + look.Z)) collider.AssemblyAngularVelocity = ZERO end local function getMovementVelocity(prevVelocity, accelerate, maxVelocity) local accelDir = currentAccelDir if accelDir == ZERO then return prevVelocity end local projVel = prevVelocity:Dot(accelDir) local accelVel = accelerate * dt if projVel + accelVel > maxVelocity then accelVel = math.max(maxVelocity - projVel, 0) end return prevVelocity + accelDir * accelVel end local function getMovementVelocityForce() return Vector3.new(movementVelocityForce, 0, movementVelocityForce) end local function getMovementVelocityAirForce() local accelDir = currentAccelDir if accelDir == ZERO then return ZERO end return Vector3.new( movementVelocityForce * math.abs(accelDir.X), 0, movementVelocityForce * math.abs(accelDir.Z) ) end local function air() movementPosition.maxForce = ZERO movementVelocity.velocity = getMovementVelocity(collider.AssemblyLinearVelocity, CONFIG.AirAccelerate, CONFIG.AirWishSpeed) movementVelocity.maxForce = getMovementVelocityAirForce() end local function jump() local v = collider.AssemblyLinearVelocity collider.AssemblyLinearVelocity = Vector3.new(v.X, jumpVelocity, v.Z) air() end local function run(hitPosition) local v = collider.AssemblyLinearVelocity local playerSpeed = v.Magnitude local mVelocity = v if playerSpeed ~= 0 then local drop = playerSpeed * CONFIG.Friction * dt mVelocity = mVelocity * math.max(playerSpeed - drop, 0) / playerSpeed end movementPosition.position = Vector3.new(hitPosition.X, hitPosition.Y + playerTorsoToGround, hitPosition.Z) movementPosition.maxForce = Vector3.new(0, movementPositionForce, 0) movementVelocity.velocity = getMovementVelocity(mVelocity, CONFIG.GroundAccelerate, CONFIG.GroundSpeed) movementVelocity.maxForce = getMovementVelocityForce() movementVelocity.P = movementVelocityP end local MIN_GROUND_NORMAL_Y = 0.5 local function findCollisionRay() local rootPart = collider if not rootPart then return nil end local torsoCF = rootPart.CFrame local dirLen = -rayYLength local bestPart, bestPos = nil, nil for i = 1, 5 do local origin = torsoCF * RAY_OFFSETS[i] local dir = Vector3.new(0, dirLen, 0) local result = workspace:Raycast(origin, dir, raycastParams) if result and result.Normal.Y >= MIN_GROUND_NORMAL_Y then if bestPos == nil or result.Position.Y > bestPos.Y then bestPart, bestPos = result.Instance, result.Position end end end if bestPart == nil then return nil end return bestPart, bestPos end local lastDiag = 0 local lastGeomCheck = 0 local function update(deltaTime) dt = deltaTime if not collider or not collider.Parent then collider = resolveRootPart(character) if not collider then return end raycastParams.FilterDescendantsInstances = { character, camera } end protectAnimate() if os.clock() - lastGeomCheck > 2 then lastGeomCheck = os.clock() local measured = computeTorsoToGround() if measured then local t2g = measured + standOffset if math.abs(t2g - playerTorsoToGround) > 0.05 then playerTorsoToGround = t2g rayYLength = playerTorsoToGround + movementStickDistance end end if gravityForce then gravityForce.force = Vector3.new(0, (1 - gravity) * workspace.Gravity, 0) * getCharacterMass() end end cameraYaw = getYaw() cameraLook = cameraYaw.lookVector updateMoveInputSum() currentAccelDir = computeAccelDir() local hitPart, hitPosition = findCollisionRay() playerGrounded = hitPart ~= nil if wasGrounded ~= nil and playerGrounded and not wasGrounded then playLandSound() end wasGrounded = playerGrounded if humanoidRef then local shouldBlock = playerGrounded and not jumping if shouldBlock and freefallEnabled then freefallEnabled = false local state = humanoidRef:GetState() if state == Enum.HumanoidStateType.Freefall or state == Enum.HumanoidStateType.Jumping then humanoidRef:ChangeState(Enum.HumanoidStateType.Running) end humanoidRef:SetStateEnabled(Enum.HumanoidStateType.Freefall, false) elseif not shouldBlock and not freefallEnabled then freefallEnabled = true humanoidRef:SetStateEnabled(Enum.HumanoidStateType.Freefall, true) end end local wantJump = input["Space"] or mobileJumpHeld if playerGrounded and (wantJump or jumping) then jumping = true else jumping = false end setCharacterRotation() if jumping then jump() elseif playerGrounded then run(hitPosition) else air() end end local inputKeys = { ["W"] = false, ["S"] = false, ["A"] = false, ["D"] = false, ["Space"] = false, ["LMB"] = false, ["RMB"] = false, } local function onInput(inp, gameProcessedEvent) local state if inp.UserInputState == Enum.UserInputState.Begin then state = true elseif inp.UserInputState == Enum.UserInputState.End then state = false else return end local uit = inp.UserInputType if uit == Enum.UserInputType.Keyboard then local key = inp.KeyCode.Name if inputKeys[key] ~= nil then inputKeys[key] = state end elseif uit.Name:match("^Gamepad") then if inp.KeyCode == Enum.KeyCode.ButtonA then inputKeys["Space"] = state end elseif uit == Enum.UserInputType.MouseButton1 then inputKeys.LMB = state elseif uit == Enum.UserInputType.MouseButton2 then inputKeys.RMB = state end end local prevUpdateTime = os.clock() local function updateLoop() local t = os.clock() local d = t - prevUpdateTime prevUpdateTime = t if d <= 0 then d = 1/60 end update(d) end local function main() local plr = Players.LocalPlayer player = plr UserInputService.MouseIcon = "rbxassetid://10104198910" UserInputService.InputBegan:Connect(onInput) UserInputService.InputEnded:Connect(onInput) local movementStopped = false local function stopOnDeath() if movementStopped then return end movementStopped = true pcall(function() RunService:UnbindFromRenderStep("bhopUpdateLoop") end) if movementPosition then movementPosition.maxForce = ZERO end if movementVelocity then movementVelocity.maxForce = ZERO movementVelocity.velocity = ZERO end if gravityForce then gravityForce.force = ZERO end if humanoidRef then humanoidRef:SetStateEnabled(Enum.HumanoidStateType.Freefall, true) end end local function setupCharacter(char) movementStopped = false destroyLandPool() character = char humanoidRef = char:FindFirstChildOfClass("Humanoid") or char:WaitForChild("Humanoid", 10) if not humanoidRef then return end if not init(plr, workspace.CurrentCamera, inputKeys) then return end initBodyMovers() wasGrounded = nil freefallEnabled = true jumping = false dt = 1/60 RunService:BindToRenderStep("bhopUpdateLoop", 1, updateLoop) task.spawn(function() task.wait(0.2) playSpawnSound() end) task.spawn(function() -- Ждём именно ноги/ступни (без fallback на HumanoidRootPart) local t0 = os.clock() while os.clock() - t0 < 15 and #getFootParts(character, false) == 0 do if character ~= char then return end task.wait(0.1) end if character == char then buildLandPool() end end) if humanoidRef.Died then humanoidRef.Died:Connect(stopOnDeath) end if humanoidRef.HealthChanged then humanoidRef.HealthChanged:Connect(function(health) if health <= 0 then stopOnDeath() end end) end end local char = script.Parent if not char or not char:IsA("Model") or char.Parent == workspace then char = plr.Character or plr.CharacterAdded:Wait() end setupCharacter(char) if plr and plr.CharacterAdded then plr.CharacterAdded:Connect(function(newChar) if not newChar.Parent then newChar.AncestryChanged:Wait() end task.wait(0.1) setupCharacter(newChar) end) end end if script and script.Destroying then script.Destroying:Connect(function() pcall(function() RunService:UnbindFromRenderStep("bhopUpdateLoop") end) end) end main()