Character not tilting properly in move direction (R6)

So I have some code which tilts the players character in the direction they are walking in. It works perfectly in R15, however it doesn’t seem to function properly in R6 due to a limitation with joints.

This is the code (R15 version):

-- services
local runService = game:GetService("RunService")

-- variables
local humanoidRootPart = script.Parent.Parent:WaitForChild("HumanoidRootPart")
local lowerTorso = script.Parent.Parent:WaitForChild("LowerTorso")
local upperTorso = script.Parent.Parent:WaitForChild("UpperTorso")
local humanoid = script.Parent.Parent:WaitForChild("Humanoid")

local rootJoint = lowerTorso:WaitForChild("Root")
local waistJoint = upperTorso:WaitForChild("Waist")

local originalRootJointC0 = rootJoint.C0
local originalWaistJointC0 = waistJoint.C0

local rotationSpeed = 8
local rotationAmount = 0.3

-- functions
runService.RenderStepped:Connect(function(deltaTime: number)
	local direction = humanoidRootPart.CFrame:VectorToObjectSpace(humanoid.MoveDirection)
	
	rootJoint.C0 = rootJoint.C0:Lerp(originalRootJointC0 * CFrame.Angles(0, 0, -(direction.X * rotationAmount)), deltaTime * rotationSpeed)
	waistJoint.C0 = waistJoint.C0:Lerp(originalWaistJointC0 * CFrame.Angles(0, 0, -(direction.X * rotationAmount)), deltaTime * rotationSpeed)
end)

And this is the R6 version (The one which doesn’t properly work):

-- services
local runService = game:GetService("RunService")

-- variables
local humanoidRootPart = script.Parent.Parent:WaitForChild("HumanoidRootPart")
local humanoid = script.Parent.Parent:WaitForChild("Humanoid")

local rootJoint = humanoidRootPart:WaitForChild("RootJoint")

local originalRootJointC0 = rootJoint.C0

local rotationSpeed = 8
local rotationAmount = 0.3

-- functions
runService.RenderStepped:Connect(function(deltaTime: number)
	local direction = humanoidRootPart.CFrame:VectorToObjectSpace(humanoid.MoveDirection)
	
	rootJoint.C0 = rootJoint.C0:Lerp(originalRootJointC0 * CFrame.Angles(0, 0, -(direction.X * rotationAmount)), deltaTime * rotationSpeed)
end)

I have no idea how to properly make this work. I’ve searched for a bit on the devforum but to no avail. I also tried to mess around with some properties/methods but again to no avail. Any help would be greatly appreciated. Thanks

this topic was already created, but heres the tilt script solution that I found:

root = script.Parent:WaitForChild("HumanoidRootPart")
local dir, vel
local rlangle = 0
local fbangle = 0
local original = root.RootJoint.C0
--looping code
hb = game:GetService("RunService")

hb.Heartbeat:Connect(function()
	vel = root.Velocity * Vector3.new(1,0,1)
	if vel.Magnitude > 2 and vel.Magnitude < 20 then
		dir = vel.Unit
		rlangle = root.CFrame.RightVector:Dot(dir)/10 --will be between -1 and 1 based on how far off it is
		fbangle = root.CFrame.LookVector:Dot(dir)/10 --will be between -1 and 1 based on how far off it is
	else
		rlangle = 0
		fbangle = 0
	end

	root.RootJoint.C0 = original*CFrame.Angles(fbangle, -rlangle, 0)
end)

(original solution found here: How to tilt the character when you walk?)

The code you sent did not work however the post you referenced did work for me, thanks!

huh, weird. I pretty much copy pasted it from my script. Though maybe it was because I didn’t specify type of script, but oh well. Glad I could be of help though!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.