-- Version 25: Hybrid Velocity-Input Wall Collision Router local Players = game:GetService("Players") local RunService = game:GetService("RunService") local LocalPlayer = Players.LocalPlayer local physicsLoop = nil local renderLoop = nil local function setupAnimateEngine(character) -- Disconnect old threads upon respawn if physicsLoop then physicsLoop:Disconnect(); physicsLoop = nil end if renderLoop then renderLoop:Disconnect(); renderLoop = nil end local Figure = character local Humanoid = Figure:WaitForChild("Humanoid") local RootPart = Figure:WaitForChild("HumanoidRootPart") local Torso = Figure:WaitForChild("Torso") local RightShoulder = Torso:WaitForChild("Right Shoulder", 5) local RootJoint = RootPart:WaitForChild("RootJoint", 5) -- Store base resting matrix safely local originalC0 = RightShoulder and RightShoulder.C0 or CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0) -- Destroy native Roblox animate scripts instantly local nativeAnimate = Figure:WaitForChild("Animate", 5) if nativeAnimate then nativeAnimate.Disabled = true nativeAnimate:Destroy() end -- Clean out any conflicting track structures local Animator = Humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator", Humanoid) for _, track in ipairs(Animator:GetPlayingAnimationTracks()) do track:Stop(0) end -- Initialize clean movement tracks local anims = { idle = Instance.new("Animation"), walk = Instance.new("Animation"), jump = Instance.new("Animation"), fall = Instance.new("Animation"), climb = Instance.new("Animation"), swim = Instance.new("Animation"), sit = Instance.new("Animation") } anims.idle.AnimationId = "rbxassetid://161100084" anims.walk.AnimationId = "rbxassetid://161210451" anims.jump.AnimationId = "rbxassetid://165167557" anims.fall.AnimationId = "rbxassetid://165167632" anims.climb.AnimationId = "rbxassetid://161235826" anims.swim.AnimationId = "rbxassetid://144078604" anims.sit.AnimationId = "rbxassetid://178130996" local tracks = {} for name, anim in pairs(anims) do tracks[name] = Animator:LoadAnimation(anim) tracks[name].Priority = Enum.AnimationPriority.Action3 end local currentTrack = nil local currentPose = "Idle" local isHoldingTool = false local armLiftProgress = 0 local jumpTime = 0 local JUMP_DURATION = 0.31 -- Tool Detection local function checkToolState() local toolFound = false for _, child in ipairs(Figure:GetChildren()) do if child:IsA("Tool") then toolFound = true break end end isHoldingTool = toolFound end checkToolState() local toolAddedConn = Figure.ChildAdded:Connect(function(child) if child:IsA("Tool") then isHoldingTool = true end end) local toolRemovedConn = Figure.ChildRemoved:Connect(function(child) if child:IsA("Tool") then task.defer(checkToolState) end end) local function playTrack(name) local targetTrack = tracks[name] if not targetTrack then return end if currentTrack ~= targetTrack then if currentTrack then currentTrack:Stop(0.1) end currentTrack = targetTrack if name == "walk" or name == "idle" or name == "climb" or name == "swim" or name == "sit" then currentTrack.Looped = true else currentTrack.Looped = false end currentTrack:Play(0.1) else if not currentTrack.IsPlaying then currentTrack:Play(0) end end end -- Core Jump Listener local stateConn = Humanoid.StateChanged:Connect(function(_, newState) if newState == Enum.HumanoidStateType.Jumping then currentPose = "Jumping" jumpTime = os.clock() end end) -- LOOP 1: Advanced Inverse-Kinematics Torso Lock (Stepped Override) renderLoop = RunService.Stepped:Connect(function(_, deltaTime) deltaTime = deltaTime or (1/60) if not Figure or not Figure:IsDescendantOf(workspace) or Humanoid.Health <= 0 then if renderLoop then renderLoop:Disconnect(); renderLoop = nil end return end local shouldRaiseArm = isHoldingTool and currentPose ~= "Climbing" and currentPose ~= "Swimming" if RightShoulder and RootJoint and Torso and RootPart then RightShoulder.Transform = RightShoulder.Transform:Lerp(CFrame.new(), armLiftProgress) if shouldRaiseArm then armLiftProgress = math.min(1, armLiftProgress + (deltaTime * 7)) local currentTorsoRotation = (RootPart.CFrame:Inverse() * Torso.CFrame).Rotation local counterTwist = currentTorsoRotation:Inverse() local shoulderPos = CFrame.new(originalC0.Position) local shoulderRot = originalC0.Rotation local stabilizedC0 = shoulderPos * counterTwist * shoulderRot * CFrame.Angles(0, 0, math.rad(90)) RightShoulder.C0 = originalC0:Lerp(stabilizedC0, armLiftProgress) else armLiftProgress = math.max(0, armLiftProgress - (deltaTime * 7)) local targetAngle = math.rad(90) * armLiftProgress RightShoulder.C0 = originalC0 * CFrame.Angles(0, 0, targetAngle) end end end) -- LOOP 2: Golden Standard State Engine Router physicsLoop = RunService.PostSimulation:Connect(function() if not Figure or not Figure:IsDescendantOf(workspace) or Humanoid.Health <= 0 then if toolAddedConn then toolAddedConn:Disconnect() end if toolRemovedConn then toolRemovedConn:Disconnect() end if stateConn then stateConn:Disconnect() end if physicsLoop then physicsLoop:Disconnect(); physicsLoop = nil end return end local currentState = Humanoid:GetState() local isMidAir = (Humanoid.FloorMaterial == Enum.Material.Air) -- FIXED: Calculate actual horizontal physical velocity magnitude (ignoring gravity/Y axis) local horizontalVelocity = (RootPart.AssemblyLinearVelocity * Vector3.new(1, 0, 1)).Magnitude -- FIXED: Must have intent to move AND actually be physically moving through space local isMoving = (Humanoid.MoveDirection.Magnitude > 0) and (horizontalVelocity > 0.8) -- Strictly ordered hierarchy evaluation if currentState == Enum.HumanoidStateType.Seated then currentPose = "Seated" elseif currentState == Enum.HumanoidStateType.Swimming then currentPose = "Swimming" elseif currentState == Enum.HumanoidStateType.Climbing then currentPose = "Climbing" elseif currentPose == "Jumping" then if os.clock() - jumpTime > JUMP_DURATION then currentPose = "FreeFall" end elseif isMidAir then currentPose = "FreeFall" else -- Explicitly on solid ground if isMoving then currentPose = "Walk" else currentPose = "Idle" end end -- Track playback engine evaluations if currentPose == "Walk" then playTrack("walk") if currentTrack then currentTrack:AdjustSpeed(Humanoid.WalkSpeed / 16) end elseif currentPose == "Idle" then playTrack("idle") elseif currentPose == "Seated" then playTrack("sit") elseif currentPose == "Jumping" then playTrack("jump") elseif currentPose == "FreeFall" then playTrack("fall") elseif currentPose == "Swimming" then playTrack("swim") if currentTrack then if Torso.AssemblyLinearVelocity.Magnitude > 0.5 then currentTrack:AdjustSpeed(1) else currentTrack:AdjustSpeed(0.2) end end elseif currentPose == "Climbing" then playTrack("climb") if currentTrack then if math.abs(Torso.AssemblyLinearVelocity.Y) > 0.2 then currentTrack:AdjustSpeed(1) else currentTrack:AdjustSpeed(0) end end end end) end if LocalPlayer.Character then task.spawn(setupAnimateEngine, LocalPlayer.Character) end LocalPlayer.CharacterAdded:Connect(function(newCharacter) setupAnimateEngine(newCharacter) end)