How to set a max torque to a specific axis on a AlignOrientation?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to set a max torque on a specific axis on AlignOrientation.
  2. What is the issue? Include screenshots / videos if possible!
    AlignOrientations use a number instead of a vector3 so I can only set the max torque on all of them.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried looking at what other people did but it didn’t seem to work out for me.

My Current code:

local hrp = character:WaitForChild("HumanoidRootPart")
local Humanoid = character:WaitForChild("Humanoid")
local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

local animation = script:WaitForChild("Slide")
local AniTrack = Humanoid:LoadAnimation(animation)
local thingstoignore = {}
local tweenService = game:GetService("TweenService")
local sliding = false
local DebrisFolder = nil

CJ = false

Humanoid.StateChanged:Connect(function(OldState, NewState)
	if NewState == Enum.HumanoidStateType.Jumping then
		CJ = true
	elseif NewState == Enum.HumanoidStateType.Freefall then
		CJ = true
	else
		if NewState ~= Enum.HumanoidStateType.Jumping and NewState ~= Enum.HumanoidStateType.Freefall then
			CJ = false
		end
	end
end)

local function StartSlide()
	if thingstoignore then
		for i, v in pairs(workspace.Characters:GetChildren()) do
			table.insert(thingstoignore, v)
		end

		for i, v in pairs(workspace:GetChildren()) do
			if v:IsA("Part") and v.Name == "hitbox" then
				table.insert(thingstoignore, v)
			end
		end
	end
	
	local raycastParams = RaycastParams.new()
	local thingstoignore = {}
	
	if not workspace:FindFirstChild("Debris") then
		DebrisFolder = Instance.new("Folder")
		DebrisFolder.Name = "Debris"
		DebrisFolder.Parent = workspace
	else
		DebrisFolder = workspace:FindFirstChild("Debris")
	end

	if thingstoignore then
		for i, v in pairs(workspace.Characters:GetChildren()) do
			table.insert(thingstoignore, v)
		end

		for i, v in pairs(DebrisFolder:GetChildren()) do
			table.insert(thingstoignore, v)
		end

		for i, v in pairs(workspace:GetChildren()) do
			if v:IsA("Part") and v.Name == "hitbox" then
				table.insert(thingstoignore, v)
			end
		end
	end

	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.FilterDescendantsInstances = {thingstoignore}
	raycastParams.IgnoreWater = true
	
	local StartingSpeed = 65
	local tiltstrength
	
	local Alignment = Instance.new("AlignOrientation")
	Alignment.Parent = hrp
	Alignment.Attachment0 = hrp.RootAttachment
	Alignment.Mode = Enum.OrientationAlignmentMode.OneAttachment
	Alignment.Responsiveness = 100
	Alignment.MaxTorque = 40000 -- how to set to a specific axis?
	Alignment.MaxAngularVelocity = 100
	Alignment.RigidityEnabled = false

	connection = RS.Stepped:Connect(function()
		
			local characterRightCF = hrp.CFrame * CFrame.new(0,0,0)
			
			local raycastresult = workspace:Raycast(characterRightCF.Position,Vector3.new(0,-5,0), raycastParams)

			if raycastresult then
				local normal = raycastresult.Normal
				local forward = hrp.CFrame.LookVector
				local right = forward:Cross(normal)
				local newCF = CFrame.fromMatrix(raycastresult.Position, right, normal)
				
				CFrameResult = CFrame.fromMatrix(
					raycastresult.Position, -- POSITION OF THE OBJECT
					right, -- RightVector
					normal -- RayCast Normal
				)

				Alignment.CFrame = CFrameResult * CFrame.new(0,0,0)
			
				
				tiltstrength = -raycastresult.Normal:Cross(hrp.CFrame.RightVector).Y
				
				print(-raycastresult.Normal:Cross(hrp.CFrame.RightVector).Y) -- Strength of lookvector tilt
			else
				tiltstrength = nil
			end
			
		print(tiltstrength)	
		
		if sliding and StartingSpeed > 0 then
			Alignment.Enabled = true
			print(StartingSpeed)
			
			if tiltstrength == nil then
				Alignment.Enabled = false
				tiltstrength = 0
			end
			
			if tiltstrength > 0 then
				StartingSpeed = math.clamp(StartingSpeed + tiltstrength * 20 - 2.5, 0, 125)
			else
				StartingSpeed = math.clamp(StartingSpeed + tiltstrength * 10 - 2, 0, 125)
			end
		else
			connection:Disconnect()
			StartingSpeed = 0
			AniTrack:stop()
			sliding = false
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
			for _, descendant in pairs(character:GetDescendants()) do
				if descendant:IsA("BodyVelocity") then
					descendant:Destroy()
				end
				if descendant:IsA("AlignOrientation") then
					descendant:Destroy()
				end
			end
		end
	end)
end

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end

	if input.KeyCode == Enum.KeyCode.C and CJ == false then
		AniTrack:play()
		StartSlide()
		sliding = true
	end
end)

UIS.InputEnded:Connect(function(input, gameProcessed)
	if gameProcessed then return end

	if input.KeyCode == Enum.KeyCode.C then
		AniTrack:stop()
		sliding = false
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
		for _, descendant in pairs(character:GetDescendants()) do
			if descendant:IsA("BodyVelocity") then
				descendant:Destroy()
			end
			if descendant:IsA("AlignOrientation") then
				descendant:Destroy()
			end
		end
	end
end)

Bump, since this problem is really slowing development

You can’t exactly set the max torque on a specific axis, but you can use alternatives

--Somewhere at the top of the script
local function Lerp(a, b, c)
    return a + (b - a) * c
end

--Where you get the orientation of both the original value, and the new value
local X, Y, Z = CFrameResult:ToOrientation()
local NX, NY, NZ = Alignment.CFrame:ToOrientation()

--I'm using Y as my example for how to slow the torque
Alignment.CFrame = CFrame.Angles(X,  Lerp(NY, Y, 0.5), Z) * CFrame.new(0,0,0)
--Moves whichever value by a specific amount, not exactly setting the torque but slowing it down.

--However, if you need to speed it up
Alignment.CFrame = CFrame.Angles(X,  math.clamp(Lerp(NY, Y*2, 1), -math.abs(Y), math.abs(Y)), Z) * CFrame.new(0,0,0)
--Theoretically speeds up the rotation.

I don’t have a way to test right now, but this should work.
Let me know if this helps!

I’ll test it and see how it works, Thanks

It didn’t seem to work since I’m trying to get rid of the force that comes from the X and Z orientations, that way the character can turn with their arrow keys. You know how when you apply a align orientation to a hrp the arrow key’s force isn’t strong enough to turn the character? I want to make it so that the force applied by the AlignOrientation isn’t overpowering the turning force, while still keeping the Y axis’s force.