How to detect if a player is moving (even when airborne)

Hi!

I have a working distance script, but I need to make it detect when the player is moving in the air and on the ground. My code is below:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local part1 = Character:WaitForChild("HumanoidRootPart")
local part2 = game.Workspace:FindFirstChild("KSAN1")
local txt = part2.BillboardGui.txtDistance

local Humanoid = Character:WaitForChild("Humanoid")
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if Humanoid.MoveDirection.Magnitude <= 0 then return end
	local distance = (part1.Position - part2.Position).Magnitude
	txt.Text = ("%.2f"):format((distance/20000)).."km"
end)



The script works when a player is walking, but it does not work when they are, say, flying an aircraft. This is a big problem since my game is an aviation game, so I need the script to update when the player is moving not only in 2D but in 3D as well. Any help is appreciated!

Thanks in advance.

The humanoid has a property called movedirection Humanoid.MoveDirection, works in air and in ground

if Humanoid.MoveDirection.Magnitude > 0  then
	local distance = (part1.Position - part2.Position).Magnitude
	txt.Text = ("%.2f"):format((distance/20000)).."km"
end

The move direction changes also when humanoid root part its anchored

In the forum topics I searched, MoveDirection is only 2D.

who said it needs to be 3D, the y axis for what you want to use??

the player cant move the y axis, just jumping

you want to detect the y axis also??