local chr = owner.Character
local root = chr.HumanoidRootPart
local hum = chr.Humanoid
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
raycastParams.RespectCanCollide = true
raycastParams.FilterDescendantsInstances = {chr}
function joint(p0, p1, c0, c1, name)
local w = Instance.new("Weld")
w.Part0 = p0
w.Part1 = p1
w.C0 = c0
w.C1 = c1
w.Name = name
w.Parent = p0
return w
end
local nk = joint(chr.Torso, chr.Head, CFrame.new(0, 1, 0), CFrame.new(0, -0.5, 0), "Neck")
local rj = joint(root, chr.Torso, CFrame.new(), CFrame.new(), "RootJoint")
local rs = joint(chr.Torso, chr:FindFirstChild("Right Arm"), CFrame.new(1.5, 0.5, 0), CFrame.new(0, 0.5, 0), "Right Shoulder")
local ls = joint(chr.Torso, chr:FindFirstChild("Left Arm"), CFrame.new(-1.5, 0.5, 0), CFrame.new(0, 0.5, 0), "Left Shoulder")
local rh = joint(chr.Torso, chr:FindFirstChild("Right Leg"), CFrame.new(0.5, -1, 0), CFrame.new(0, 1, 0), "Right Hip")
local lh = joint(chr.Torso, chr:FindFirstChild("Left Leg"), CFrame.new(-0.5, -1, 0), CFrame.new(0, 1, 0), "Left Hip")
local rsc0, lsc0, rhc0, lhc0, rjc0, nkc0 = rs.C0, ls.C0, rh.C0, lh.C0, rj.C0, nk.C0
local t = os.clock()
local exactVel = 0
local vel = 0
local animMove = false
local action = "Walk"
local animTable = {
["Idle"] = function()
return {
rj = rjc0,
nk = nkc0,
ls = lsc0,
rs = rsc0,
lh = lhc0,
rh = rhc0
}
end;
["Walk"] = function()
return {
rj = rjc0 * CFrame.new(0, math.sin(t / 2.5) / 20, 0) *
CFrame.Angles(-math.cos(t / 2.5) / 20 * -(exactVel.Z / 13) + (exactVel.Z / 150), 0, -math.cos(t / 2.5) / 20 * (exactVel.X / 13) - (exactVel.X) / 150),
nk = nkc0,
ls = lsc0 * CFrame.Angles(-math.sin(t / 5) / 2 * (exactVel.Z / 13), math.rad(3), -math.rad(5)),
rs = rsc0 * CFrame.Angles(math.sin(t / 5) / 2 * (exactVel.Z / 13), -math.rad(3), math.rad(5)),
lh = lhc0 * CFrame.new(0, -math.cos(t / 5) / 4, -0.125 + math.sin(t / 5) / 3 * (-exactVel.Z / 13)) *
CFrame.Angles(math.min(-math.sin(t / 5), 0.3) * (-exactVel.Z / 13), math.rad(3), -math.rad(3)) *
CFrame.new(math.sin(t / 5) / 4 * -(exactVel.X / 13), 0, 0) *
CFrame.Angles(-exactVel.X / 100, 0, -math.sin(t / 5) / 2 * (exactVel.X / 13)),
rh = rhc0 * CFrame.new(0, math.cos(t / 5) / 4, -0.125 - math.sin(t / 5) / 3 * (-exactVel.Z / 13)) *
CFrame.Angles(math.min(math.sin(t / 5), 0.3) * (-exactVel.Z / 13), -math.rad(3), math.rad(3)) *
CFrame.new(-math.sin(t / 5) / 4 * -(exactVel.X / 13), 0, 0) *
CFrame.Angles(exactVel.X / 100, 0, math.sin(t / 5) / 2 * (exactVel.X / 13)),
}
end
}
local joints = {["rj"] = rj, ["nk"] = nk, ["rs"] = rs, ["ls"] = ls, ["rh"] = rh, ["lh"] = lh}
game:GetService("RunService").PostSimulation:Connect(function(dt)
t = os.clock() * 60
exactVel = CFrame.new(root.CFrame:VectorToObjectSpace(root.Velocity))
vel = Vector3.new(math.clamp(exactVel.x, -32, 32), math.clamp(exactVel.y, -32, 32), math.clamp(exactVel.z, -32, 32))
if animMove then
if hum:GetState() ~= Enum.HumanoidStateType.Climbing then
if not hum.Sit then
if hum.FloorMaterial == Enum.Material.Air then
action = "Fall"
else
action = hum.MoveDirection.Magnitude > 0 and "Walk" or "Idle"
end
else
action = "Sit"
end
else
if math.abs(vel.Y) > 0 then
action = "Climb"
end
end
end
for i, v in next, joints do
v.C0 = v.C0:Lerp(animTable[action]()[i], 0.3 * dt * 60)
end
end)