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

Hello,

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 = Vector3.new()

function onUpdate(dt)

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

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


end;

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(Vector3.new(0,1,0) )
local Cross2 = Point:Cross(Cross1)
return  Cross1, Point, Cross2
end
local X,Y,Z = PointTopSide(ray.Normal)
RootJoint.C0 = CFrame.fromMatrix(RootJoint.C0.Position,X,Y,Z)
1 Like