Humanoid MaxSlopeAngle Event

I would like to see a new event for the humanoid that fires when a player slides down a slope (based on the humanoid’s MaxSlopeAngle). Or, alternatively, a new humanoid state that fires under the same circumstances.

5 Likes

In the meantime, here’s a little trick to get the surface angle! I googled “normal to angle” and various other searches before finding a solution that was simple and worked. I’m awful with math, so I couldn’t explain to you why this works, but I’m sure someone here could easily explain it. The source of my solution is linked below the Lua code.

What’s happening in the code:

  • Get position of Torso
  • Cast ray straight down
  • Get resultant surface normal
  • Run normal through the GetSurfaceAngle function & output surface angle
local player = game.Players.LocalPlayer
local up = Vector3.FromNormalId(Enum.NormalId.Top)

function GetSurfaceAngle(normalVector)
	return math.acos(normalVector.Y)
end

function GetSurfaceAngleUnderCharacter()
	if (player.Character and player.Character:FindFirstChild("Torso")) then
		local pos = player.Character.Torso.Position
		local ray = Ray.new(pos, Vector3.new(0, -50, 0))
		local hit, pos, norm = game.Workspace:FindPartOnRay(ray, player.Character, true)
		if (hit) then
			local angle = GetSurfaceAngle(norm)
			return angle
		end
	end
end

--------------------------------------------------

-- Example usage:
while (true) do
	local angle = GetSurfaceAngleUnderCharacter()
	if (angle) then
		local angleDegrees = math.deg(angle)
		print(("Surface Angle: %.1f degrees"):format(angleDegrees))
	end
	wait(1)
end

Where I got this algorithm: http://forum.devmaster.net/t/angles-from-normal-how/9124/12

6 Likes

Correct me if I’m wrong, but doesn’t the FreeFalling event start firing?

Late reply, but both yes and no - it also depends on the slope’s angle. If the angle is very steep, it’ll fire over and over. If not, it’ll print the FreeFalling event to be false, just like when you land… so it’s not useful for this, sadly :confused: