What is the issue?
No solution on the devforum seems to provide the same result with R6, or anything even generally close to functional (see results screenshots bellow).
What solutions have you tried so far?
Most of these pertain to R15 avatars, and ones that don’t do not work either way. Some methods use a torque or some other kind of arcane combination of physics object, but this leads to the player avatar experiencing bizarre physics byproducts
Attempted methods: #1 (current)
The script from this post SHOULD help you. It helped me afterall when i had the exact same problem as you!
The script
local char = script.Parent
local rootPart = char:WaitForChild("HumanoidRootPart")
local xzGyro = Instance.new("BodyGyro")
local yGyro = Instance.new("BodyGyro")
yGyro.MaxTorque = Vector3.new(0,3e5,0)
yGyro.P = 5e5
xzGyro.MaxTorque = Vector3.new(3e5,0,3e5)
xzGyro.P = 5e5
xzGyro.Parent = rootPart
while wait(0.5) do
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Blacklist
local result = workspace:Raycast(rootPart.Position, Vector3.new(0,-10,0), params)
yGyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + char.Humanoid.MoveDirection*10)
if (result) then
print(result.Normal)
local currentRightVector = rootPart.CFrame.RightVector
local upVector = result.Normal
local newFacialVector = currentRightVector:Cross(upVector)
xzGyro.CFrame = CFrame.fromMatrix(rootPart.Position, currentRightVector, upVector, newFacialVector)
end
end
And yes, it might be old BUT it still worked perfectly.
What offset would be fit for a regular R6 avatar? I’ve attempted this before, but the best I’ve managed was to offset so that the player begins upright at flat surfaces, but when trying to walk on any kind of slope, it still orients the character incorrectly (upside down with the demonstration slope, in that case).
local RunService = game:GetService("RunService")
local Character = script.Parent
local HumanoidRootPart:BasePart = Character:WaitForChild("HumanoidRootPart")
local RootJoint = HumanoidRootPart:WaitForChild("RootJoint")
local RootJointC0 = RootJoint.C0
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {Character}
RunService.RenderStepped:Connect(function(deltaTime)
local RaycastResult = workspace:Raycast(HumanoidRootPart.Position,-Vector3.yAxis*5, RayParams)
local C0Offset = CFrame.identity
if RaycastResult then
local upVector = RaycastResult.Normal
local rightVector = HumanoidRootPart.CFrame.RightVector
local backVector = -HumanoidRootPart.CFrame.LookVector
local calculationForX = CFrame.fromMatrix(Vector3.zero,rightVector,upVector)
local calculationForZ = CFrame.fromMatrix(Vector3.zero,backVector,upVector)
local x = calculationForX:ToOrientation()
local z = calculationForZ:ToOrientation()
C0Offset = CFrame.Angles(x,0,z)
end
RootJoint.C0 = RootJoint.C0:Lerp(C0Offset*RootJointC0,deltaTime*10)
end)