I am trying to make a tilting code where it tilts the player into the direction they are moving, the code below works, but i would like to make it so it does not tilt when moving just forward, i tried that in “if MoveDirection == 0 or MoveDirection == 4 then” but it does not work, any suggestions?
local RunService = game:GetService'RunService'
local Players = game:GetService'Players'
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass'Humanoid'
local RootPart = Character:WaitForChild'HumanoidRootPart'
local RootJoint = RootPart:WaitForChild'RootJoint'
local RootC0 = RootJoint.C0
local MaxTiltAngle = 10
local Tilt = CFrame.new()
RunService.RenderStepped:Connect(function(Delta)
if Humanoid.WalkSpeed < 5 then
return nil
else
local MoveDirection = RootPart.CFrame:VectorToObjectSpace(Humanoid.MoveDirection)
if MoveDirection == 0 or MoveDirection == 4 then
return nil
else
Tilt = Tilt:Lerp(CFrame.Angles(math.rad(-MoveDirection.Z) * MaxTiltAngle, math.rad(-MoveDirection.X) * MaxTiltAngle, 0), 0.2 ^ (1 / (Delta * 60)))
RootJoint.C0 = RootC0 * Tilt
end
end
end)