i made a flight script, it works alright but you can go faster when going diagonally. i know the problem has to do with the direction being 1 and 1 etc adding up to 2 but im not sure how to fix it. any help would be appreciated

local Flight = {};
local Services = nil;

local UserInputService = game:GetService("UserInputService");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local RunService = game:GetService("RunService");
local Players = game:GetService("Players");

local client = Players.LocalPlayer;
local camera = workspace.CurrentCamera;
local space = tick();
local flying = false;
local direction = {x = 0, y = 0, z = 0};

repeat wait() until client.Character;

local function EndFlight()
	flying = false;
	client.Character.HumanoidRootPart.BodyPosition.MaxForce = Vector3.new();
	client.Character.HumanoidRootPart.BodyGyro.MaxTorque = Vector3.new();
	direction.x = 0;
	direction.y = 0;
	direction.z = 0;
end

local function StartFlight()
	flying = true;
	local BP = client.Character.HumanoidRootPart:FindFirstChild("BodyPosition") or Instance.new("BodyPosition", client.Character.HumanoidRootPart);
	BP.MaxForce = Vector3.new(500000, 500000, 500000);
	BP.D = 10;
	BP.P = 10000;

	local BG = client.Character.HumanoidRootPart:FindFirstChild("BodyGyro") or Instance.new("BodyGyro", client.Character.HumanoidRootPart);
	BG.MaxTorque = Vector3.new(500000, 500000, 500000);
	BG.D = 10;
	
	while (flying and client.Character.Humanoid:GetState() == Enum.HumanoidStateType.Freefall) do
		print((direction.x + direction.z) * 90 + 45)
		RunService.RenderStepped:wait()
		BP.Position = (client.Character.HumanoidRootPart.CFrame * CFrame.new(direction.x * 0.2, direction.y * 0.2 + 0.02, direction.z * 0.2)).p;
	end
	EndFlight();
end

function Flight.Init(services)
	Services = services;

	repeat wait() until client.Character;
	
	client.Character.Humanoid.Died:Connect(function()
		repeat wait() until client.Character.Humanoid.Health > 0;
		local BP = Instance.new("BodyPosition", client.Character.HumanoidRootPart)
		BP.MaxForce = Vector3.new()
		BP.D = 10
		BP.P = 10000
	end)
	
	UserInputService.InputBegan:Connect(function(input, processed)
		if (not processed) then
			if (input.KeyCode == Enum.KeyCode.Space) then
				if (tick() - space <= 0.5) then
					if (not flying) then
						StartFlight();
						direction.y += 1;
					else
						EndFlight();
					end
				else
					direction.y += 1;
				end
				space = tick();
			elseif (input.KeyCode == Enum.KeyCode.LeftControl and flying) then
				direction.y -= 1;
			elseif (input.KeyCode == Enum.KeyCode.W and flying) then
				direction.z -= 1;
			elseif (input.KeyCode == Enum.KeyCode.A and flying) then
				direction.x -= 1;
			elseif (input.KeyCode == Enum.KeyCode.S and flying) then
				direction.z += 1;
			elseif (input.KeyCode == Enum.KeyCode.D and flying) then
				direction.x += 1;
			end
		end
	end)
	
	UserInputService.InputEnded:Connect(function(input, processed)
		if (not processed) then
			if (input.KeyCode == Enum.KeyCode.Space and flying) then
				direction.y -= 1;
			elseif (input.KeyCode == Enum.KeyCode.LeftControl and flying) then
				direction.y += 1;
			elseif (input.KeyCode == Enum.KeyCode.W and flying) then
				direction.z += 1;
			elseif (input.KeyCode == Enum.KeyCode.A and flying) then
				direction.x += 1;
			elseif (input.KeyCode == Enum.KeyCode.S and flying) then
				direction.z -= 1;
			elseif (input.KeyCode == Enum.KeyCode.D and flying) then
				direction.x -= 1;
			end
		end
	end)
end

return Flight;