What have I messed up here?

I’m trying to get a custom character to align with the floor normal, I think I am close but it is still off and I don’t know why. I imagine it could be something to do with the original C0 which is normally at an orientation of (0, -90, 85.884), but I thought that I had covered that with the use of the defaultC0 variable. Any thoughts? Thanks!

local defaultC0 = char.FakeTorso.Joint.C0

rs.Heartbeat:Connect(function(deltaTime)
	local normalRay = workspace:Raycast(root.Position, Vector3.new(0,-5,0), raycastParams)
	if normalRay then
		local vector = root.CFrame:VectorToObjectSpace(normalRay.Normal)
		char.FakeTorso.Joint.C0 = defaultC0 * CFrame.Angles(vector.z, 0, -vector.x)
		part.CFrame = CFrame.new(root.Position, root.Position - normalRay.Normal)
	end
end)

Example of the jank in question:

gif

1 Like

Still asking this question… I’ll take a guess;
(also not a fan of heartbeat, 60 times a second with stepped is fine in 99% of cases.)

local defaultC0 = char.FakeTorso.Joint.C0

rs.Stepped:Connect(function(deltaTime)
	local normalRay = workspace:Raycast(root.Position, Vector3.new(0,-5,0), raycastParams)
	if normalRay then
		local normal = normalRay.Normal
		local targetOrientation = CFrame.lookAt(Vector3.new(), normal)
		local deltaC0 = targetOrientation:inverse() * CFrame.new()
		char.FakeTorso.Joint.C0 = defaultC0 * deltaC0
		part.CFrame = CFrame.new(root.Position, root.Position - normal)
	end
end)
1 Like

Unfortunately yes haha.

Sadly this still produces a similar result, I think it’s just something to do with the way my custom character is set up but I have no idea why :sob:

Anyway thanks for the suggestion!
(anything at all is incredibly helpful at this point)

1 Like

That was just a guess… don’t give up. To be honest I’ve never tried 4 legs.

1 Like

I have managed to get this:

terrainalignmentexample

With the code:

rs.Stepped:Connect(function()
	local result = workspace:Raycast(rootPart.Position, Vector3.new(0,-10,0), params)
	if result then
		local currentRightVector = rootPart.CFrame.RightVector
		local upVector = result.Normal
		local newFacialVector = currentRightVector:Cross(upVector)
		local cf = CFrame.fromMatrix(rootPart.Position, currentRightVector, upVector, newFacialVector)
		rootPart.CFrame = cf
	end
end)

As you can see it aligns correctly but bugs out.
I’m not really sure what to do as I don’t fully grasp the maths either haha

1 Like