Detecting if the player is going up or down a slope

Hello developers, I have just made a way to detect if the player is on a slope using raycasting, However, I now want to make a way to check if the player is moving up or down the slope. The problem with this is when the player is on a slope it will print out the same result no matter which way the player is moving.

Video of this and the result:

script:

local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {char}

run.RenderStepped:Connect(function()
	local rayResult = workspace:Raycast(hrp.CFrame.Position, -hrp.CFrame.UpVector * 5, rayParams)

	if rayResult then
		print(rayResult.Normal.Y)
	end
end)

If there is a method to checking if the player is going up or down a slope or if there is a way better method of achieving this please let me know.

1 Like

do a raycast at the feet with the direction being the movedirection, and if it returns something you’re going up the slope

What you could do is save the raycast from the last frame and in the current frame check if the raycast position is either higher or lower than the last raycast position. This way you can tell if the player is moving up, down, or not moving at all.