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)
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)
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