You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to set a max torque on a specific axis on AlignOrientation. -
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. -
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)