Need help matching character's torso rotation to floor normal vector


I want to make it so the character’s torso rotation matches the floor normal vector, not by simply ajusting it’s CFrame, but by adjusting the Root Joint’s C0 value (Root Joint is the Motor6D from HumanoidRootPart to Torso)

The following picture better illustrates the desired result:

What is the issue? I don’t really know how to do it ;p

This is my script so far:

local floorNormal =

function onUpdate(dt)

local rayParams =
	rayParams.FilterType = Enum.RaycastFilterType.Whitelist
	rayParams.FilterDescendantsInstances = {workspace.Level}
	local origin = hrp.Position
	local target =,-8,0)
	local raycastResult = workspace:Raycast(origin,target,rayParams)
	local hitPos = hrp.Position + target
	if raycastResult then
		hitPos = raycastResult.Position
		floorNormal = raycastResult.Normal
		floorNormal =

-- RootJoint.C0 = RootJoint.C0 * ??? i don't know what to do here


game["Run Service"].RenderStepped:Connect(onUpdate)

You are somewhat close to it all you have to do is get the root joint position and with the normal you will have to cross it.

function PointTopSide(Point)
local Cross1 = Point:Cross(,1,0) )
local Cross2 = Point:Cross(Cross1)
return  Cross1, Point, Cross2
local X,Y,Z = PointTopSide(ray.Normal)
RootJoint.C0 = CFrame.fromMatrix(RootJoint.C0.Position,X,Y,Z)
1 Like