What do you want to achieve?
i want to be able to have an idle animation play, and stop when either the walk or jumping animation is playing. i’ve come across where the idle animation will want to play while the jumping animation is starting
What is the issue?
What solutions have you tried so far?
i’ve tried to load the animation but then i come across where the jumping animation won’t play correctly when the idle was playing before it, but the walking animation plays perfectly with the jumping animation? right now i don’t have the idle code in because it just messes things up
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local walkAnim = animator:LoadAnimation(character:WaitForChild('Walking'))
local jumpAnim = animator:LoadAnimation(character:WaitForChild('Jumping'))
local idleAnim = animator:LoadAnimation(character:WaitForChild('Idle'))
humanoid.Running:Connect(function(speed)
if speed > .1 then
if not walkAnim.IsPlaying then
walkAnim:Play()
end
walkAnim:AdjustSpeed(speed/16)
else
if walkAnim.IsPlaying then
walkAnim:Stop()
end
end
end)
humanoid.StateChanged:Connect(function(old,new)
if new == Enum.HumanoidStateType.Jumping then
jumpAnim:Play()
elseif new == Enum.HumanoidStateType.Landed then
jumpAnim:Stop()
end
end)```
use rootPart.AssemblyLinearVelocity.Magnitude. check if it is zero, and if it is, play the idle animation. otherwise play the walking animation. very crude way of doing this but someone will definitely reply with a better idea
rootpart:GetPropertyChangedSignal("AssemblyLinearVelocity"):Connect(function(Value)
local Velocity = Value.Magnitude or 0
if Velocity > 0 then
-- play walk
elseif Velocity == 0 then
-- play idle
end
end)
cant quite remember what :GetPropertyChangedSignal’s first parameter is but it should help you enough
made a mistake, :GetPropertyChangedSignal doesn’t fire for physics updates like velocity so just use a runservice.heartbeat connection and check if the velocity is 0 from there.
i don’t know what that means or where to put it if i’m going to be honest, sorry if i’m being a bit but i really want to know what these things mean and how to put them in
local RunService = game:GetService("RunService")
---... your existing code
local function animateVelocity(Velocity)
if Velocity > 0 then
-- play walk
else
-- play idle
end
end
RunService.Heartbeat:Connect(function()
local currentVelo = RootPart.AssemblyLinearVelocity.Magnitude -- assuming you referenced your rootpart already
animateVelocity(currentVelo)
end)
local character = script.Parent
local RunService = game:GetService("RunService")
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local walkAnim = animator:LoadAnimation(character:WaitForChild('Walking'))
local jumpAnim = animator:LoadAnimation(character:WaitForChild('Jumping'))
local idleAnim = animator:LoadAnimation(character:WaitForChild('Idle'))
humanoid.Running:Connect(function(speed)
if speed > .1 then
if not walkAnim.IsPlaying then
walkAnim:Play()
end
walkAnim:AdjustSpeed(speed/16)
else
if walkAnim.IsPlaying then
walkAnim:Stop()
end
end
end)
humanoid.StateChanged:Connect(function(old,new)
if new == Enum.HumanoidStateType.Jumping then
jumpAnim:Play()
elseif new == Enum.HumanoidStateType.Landed then
jumpAnim:Stop()
end
end)
local function animateVelocity(Velocity)
if Velocity > 0 then
walkAnim:Play()
else
idleAnim:Play()
end
end
RunService.Heartbeat:Connect(function()
local currentVelo = humanoid.AssemblyLinearVelocity.Magnitude
animateVelocity(currentVelo)
end)
yea but then it gives a red underline and still doesn’t work? at least with the humanoid it doesn’t have the red? i can’t tell if it’s better with the humanoid
right… i forgot you were a beginner. no worries! you just have to reference it where you put RunService.
local RunService = game:GetService("RunService")
local RootPart = character:FindFirstChild("HumanoidRootPart")
red line under something means Luau is trying to tell you something is wrong with what you typed, in your case you didn’t have a reference to RootPart, so it thinks there is no RootPart.
local character = script.Parent
local RunService = game:GetService("RunService")
local RootPart = character:FindFirstChild("HumanoidRootPart")
local RunService = game:GetService("RunService")
local walkAnim = animator:LoadAnimation(character:WaitForChild('Walking'))
local jumpAnim = animator:LoadAnimation(character:WaitForChild('Jumping'))
local idleAnim = animator:LoadAnimation(character:WaitForChild('Idle'))
RootPart.Running:Connect(function(speed)
if speed > .1 then
if not walkAnim.IsPlaying then
walkAnim:Play()
end
walkAnim:AdjustSpeed(speed/16)
else
if walkAnim.IsPlaying then
walkAnim:Stop()
end
end
end)
RootPart.StateChanged:Connect(function(old,new)
if new == Enum.HumanoidStateType.Jumping then
jumpAnim:Play()
elseif new == Enum.HumanoidStateType.Landed then
jumpAnim:Stop()
end
end)
local function animateVelocity(Velocity)
if Velocity > 0 then
walkAnim:Play()
else
idleAnim:Play()
end
end
RunService.Heartbeat:Connect(function()
local currentVelo = RootPart.AssemblyLinearVelocity.Magnitude
animateVelocity(currentVelo)
end)
'm just going to keep it at wraps for now, thank you so much for helping even if me not knowing how half of this works probably contributed to it not working- sorry again if this felt like a waste i promise i am trying to learn this all
if anyone else finds out what i am doing wrong lemme know or if there is other code to use
Hey there! Is there a particular reason why you’re using your own script for your custom animations? Why don’t you simply modify the in-built animate script to work with your rig and use custom animations instead of the pre-defined default Roblox animations?