local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- ID ваших анимаций
local walkAnimId = "rbxassetid://ID_ВАШЕЙ_АНИМАЦИИ_ХОДЬБЫ"
local runAnimId = "rbxassetid://ID_ВАШЕЙ_АНИМАЦИИ_БЕГА"
local walkAnimation
local runAnimation
local currentAnimation
-- Функция загрузки анимаций
local function loadAnimations()
walkAnimation = animator:LoadAnimation(Instance.new("Animation"))
walkAnimation.AnimationId = walkAnimId
runAnimation = animator:LoadAnimation(Instance.new("Animation"))
runAnimation.AnimationId = runAnimId
end
loadAnimations()
local function updateAnimation()
local moveDirection = humanoid.MoveDirection
local speed = moveDirection.Magnitude
if speed > 0 then
if speed > 3 then -- Порог для бега (настраивайте)
if currentAnimation ~= "run" then
if currentAnimation then
currentAnimation:Stop()
end
runAnimation:Play()
currentAnimation = "run"
end
else
if currentAnimation ~= "walk" then
if currentAnimation then
currentAnimation:Stop()
end
walkAnimation:Play()
currentAnimation = "walk"
end
end
else
if currentAnimation then
currentAnimation:Stop()
currentAnimation = nil
end
end
end
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Running or newState == Enum.HumanoidStateType.Walking or newState == Enum.HumanoidStateType.Landed then
updateAnimation()
end
end)
game:GetService("RunService").RenderStepped:Connect(updateAnimation)
Создайте LocalScript: В Roblox Studio, в StarterCharacterScripts создайте новый LocalScript (локальный скрипт).
Скопируйте код: Скопируйте вышеуказанный код в этот LocalScript.
Замените ID анимаций:
Замените "rbxassetid://ID_ВАШЕЙ_АНИМАЦИИ_ХОДЬБЫ" на ID вашей анимации ходьбы.
Замените "rbxassetid://ID_ВАШЕЙ_АНИМАЦИИ_БЕГА" на ID вашей анимации бега.
Запустите игру: Протестируйте игру, и анимация должна переключаться между ходьбой и бегом в зависимости от движения персонажа.