Adjusting player angle to the floor's angle

Currently I am trying to make movement up roblox terrain look smoother, the issue is that the terrain’s angle changes a lot and very minimally, how could I make it look less jumpy? This is what I have so far:

https://gyazo.com/d8b516d17197ddb500e211a967ca0c9f


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() do
	
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {char}
	params.FilterType = Enum.RaycastFilterType.Exclude
	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

Help appreciated, thanks!

you can adjust the dampening and power values of the body gyro to make it smoother. Alternatively, you can lerp the newFacialVector with the previous newFacialVector.

2 Likes

Works amazing, don’t know how I missed it… Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.