Player wont stay on the slope when on a downward slope

So I’ve been trying to make when a player is on a downward slope the player stays on it instead of falling off of it. I’ve tried using Bodymovers but it doesn’t really work. Does anyone know any other solution?

1 Like

https://developer.roblox.com/en-us/api-reference/property/Humanoid/MaxSlopeAngle

1 Like

Isn’t that for walking up slopes?

Would you mind sharing a video of the problem you’re encountering?

1 Like

https://gyazo.com/95403a2ff37a02884f634d253a1f133f
I’ve tried using Egomoose’s gravity controller but it breaks the engine and walks on non-collision parts.

you might try making a ray under the character then moving the character downwards where the ray hit in a renderstepped function(not sure if it would be real janky)

Yeah so after some testing out i have made this piece of code

local RS = game:GetService("RunService")
local player = game.Players.LocalPlayer
local char = player.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local Hum = char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local deb = false

local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {char:GetChildren()}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist

RS.RenderStepped:Connect(function()
	if deb == false then
	local raycastResult = workspace:Raycast(hrp.Position, Vector3.new(0,-6,0), rayParams)
	if raycastResult then
			local rayPos = raycastResult.Position
			char:MoveTo(Vector3.new(rayPos.X,rayPos.Y + 4.5,rayPos.Z))
		end
	end
end)

UIS.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.Space then
		deb = true
	end
end)

Hum.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed then
		deb = false
	end
end)

Its a bit janky but works fine.

It doesn’t work well with my game
https://gyazo.com/2c933c7b5a4eb5f76a1bb4397eaab1ce

Your either using the script i wrote before i edited the message or the players character is shorter than usual.

char:MoveTo(Vector3.new(rayPos.X,rayPos.Y + 4.5,rayPos.Z)) – change the highlighted number to half of your characters height


Heres how it looks like

https://gyazo.com/f6207c88bf2ad4fb252b8709260bb496

tbh it just breaks the engine

alr i fixed the bug and this hopefully should work

local RS = game:GetService("RunService")
local player = game.Players.LocalPlayer
local char = player.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local Hum = char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local deb = false

local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {char:GetChildren()}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist

RS.RenderStepped:Connect(function()
	if Hum.MoveDirection.X > 0 or Hum.MoveDirection.X < 0 then
		if deb == false then
	local raycastResult = workspace:Raycast(hrp.Position, Vector3.new(0,-8,0), rayParams)
	if raycastResult then
			local rayPos = raycastResult.Position
			if (rayPos.Y + 4.5) < hrp.Position.Y then
				char:MoveTo(Vector3.new(rayPos.X,rayPos.Y + 4.5,rayPos.Z))
				end
			end
		end
	end
end)

UIS.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.Space then
		deb = true
	end
end)

Hum.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed then
		deb = false
	end
end)

It works well with parts but it clips through Terrian now

https://gyazo.com/a32752a13067c1cdcaedb4d3586e1c02

I’m not sure why it is happening, but this may fix it.

local RS = game:GetService("RunService")
local player = game.Players.LocalPlayer
local char = player.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local Hum = char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local deb = false
local oldPos
local posChanged = false

local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {char:GetChildren()}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist

RS.RenderStepped:Connect(function()
	if Hum.MoveDirection.X > 0 or Hum.MoveDirection.X < 0 then
	if deb == false then
	local raycastResult = workspace:Raycast(hrp.Position, Vector3.new(0,-8,0), rayParams)
	if raycastResult then
			local rayPos = raycastResult.Position
			if (rayPos.Y + 4.5) < hrp.Position.Y then
				oldPos = hrp.CFrame
				char:MoveTo(Vector3.new(rayPos.X,rayPos.Y + 4.5,rayPos.Z))
				posChanged = true
			end
			if hrp.Position.Y > rayPos.Y + 4.4 then
				if posChanged == true then
					hrp.CFrame = oldPos
				end
			end
			end
		end
	end
end)

UIS.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.Space then
		deb = true
	end
end)

Hum.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed then
		deb = false
	end
end)