I am trying to add a run animation inside of the default Animate script, because it has a run value that is never used. I added my animation and did some quick statements to make it work, but it never plays correctly and it’s very buggy. I have an acceleration system.
function playAnimation(animName, transitionTime, humanoid)
local roll = math.random(1, animTable[animName].totalWeight)
local origRoll = roll
local idx = 1
while (roll > animTable[animName][idx].weight) do
roll = roll - animTable[animName][idx].weight
idx = idx + 1
end
-- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
local anim = animTable[animName][idx].anim
-- switch animation
if (anim ~= currentAnimInstance) then
if (currentAnimTrack ~= nil) then
currentAnimTrack:Stop(transitionTime)
currentAnimTrack:Destroy()
end
currentAnimSpeed = 1.0
-- load it to the humanoid; get AnimationTrack
currentAnimTrack = humanoid:LoadAnimation(anim)
currentAnimTrack.Priority = Enum.AnimationPriority.Core
-- play the animation
currentAnimTrack:Play(transitionTime)
currentAnim = animName
currentAnimInstance = anim
-- set up keyframe name triggers
if (currentAnimKeyframeHandler ~= nil) then
currentAnimKeyframeHandler:disconnect()
end
currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
end
end
function onRunning(speed)
speed /= getRigScale()
Speed = speed
if speed > 0.01 and Humanoid.WalkSpeed < PlayerSettings.CharacterRunSpeed then
playAnimation("walk", 0.1, Humanoid)
pose = "Running"
print("walk start")
end
if speed < 0.01 then
if emoteNames[currentAnim] == nil then
playAnimation("idle", 0.1, Humanoid)
pose = "Standing"
end
end
if Humanoid.WalkSpeed >= PlayerSettings.CharacterRunSpeed then
if currentAnimInstance and currentAnimInstance.AnimationId ~= animNames['run'][1]['id'] then
print("hi")
playAnimation("run", 0.5, Humanoid)
print(currentAnimInstance.AnimationId, animNames['run'][1]['id'])
end
print("run start")
end
Found out that I had to create my own pose, so I replaced the pose Running to Walking.
function onRunning(speed)
speed /= getRigScale()
Speed = speed
if speed > 0.01 and Humanoid.WalkSpeed < PlayerSettings.CharacterRunSpeed then
playAnimation("walk", 0.1, Humanoid)
pose = "Walking"
end
if speed < 0.01 then
if emoteNames[currentAnim] == nil then
playAnimation("idle", 0.1, Humanoid)
pose = "Standing"
end
end
if Humanoid.WalkSpeed >= PlayerSettings.CharacterRunSpeed then
if currentAnimInstance and currentAnimInstance.AnimationId ~= animNames['run'][1]['id'] and speed > 0.01 then
playAnimation("run", 0.4, Humanoid)
pose = "Running"
end
end
end
function move(time)
local amplitude = 1
local frequency = 1
local deltaTime = time - lastTick
lastTick = time
local climbFudge = 0
local setAngles = false
if (jumpAnimTime > 0) then
jumpAnimTime = jumpAnimTime - deltaTime
end
if (pose == "FreeFall" and jumpAnimTime <= 0) then
playAnimation("fall", fallTransitionTime, Humanoid)
elseif (pose == "Seated") then
playAnimation("sit", 0.5, Humanoid)
return
elseif (pose == "Walking") then
playAnimation("walk", 0.1, Humanoid)
elseif (pose == "Sprinting") then
playAnimation("Running", 0.5, Humanoid)
elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
-- print("Wha " .. pose)
stopAllAnimations()
amplitude = 0.1
frequency = 1
setAngles = true
end
if (setAngles) then
local desiredAngle = amplitude * math.sin(time * frequency)
RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
RightHip:SetDesiredAngle(-desiredAngle)
LeftHip:SetDesiredAngle(-desiredAngle)
end
-- Tool Animation handling
local tool = getTool()
if tool and tool:FindFirstChild("Handle") then
local animStringValueObject = getToolAnim(tool)
if animStringValueObject then
toolAnim = animStringValueObject.Value
-- message recieved, delete StringValue
animStringValueObject.Parent = nil
toolAnimTime = time + .3
end
if time > toolAnimTime then
toolAnimTime = 0
toolAnim = "None"
end
animateTool()
else
stopToolAnimations()
toolAnim = "None"
toolAnimInstance = nil
toolAnimTime = 0
end
end