Mantling system is very unresponsive

The system that I created is very unresponsive and doesn’t detect ledges well.

Heres my code:

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local runService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")


local humanoid = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
local head = char:WaitForChild("Head")

--setting up RaycastParams
local params = RaycastParams.new()
params.FilterDescendantsInstances = char:GetDescendants()
params.FilterType = Enum.RaycastFilterType.Exclude
params.IgnoreWater = false
params.RespectCanCollide = true


UIS.InputBegan:Connect(function(input, gpe)
	if input.KeyCode == Enum.KeyCode.Space and not gpe then
		local origin = hrp.CFrame.Position 
	
		if humanoid.FloorMaterial == Enum.Material.Air then
			print('Mantle!')
			local rootOrigin = hrp.CFrame.Position
			local headOrigin = head.CFrame.Position
			local size = hrp.Size
			
			--direction
			local rootDirection = hrp.CFrame.LookVector * 3
			local headDirection = head.CFrame.LookVector * 5


			--casting the rays
			local rootResult = workspace:Blockcast(CFrame.new(rootOrigin), size, rootDirection)
			local headResult = workspace:Raycast(headOrigin,headDirection, params)
			

			--check for wanted results
			if rootResult then
				--The player is facing a ledge. You can get the position.
			hrp.CFrame = CFrame.new(rootResult.Position) + Vector3.new(0, 5, 0)
			end
			end
	end
end)

Help is appreciated.

I found a potential issue with your code, @PENG_LINMEME .
Getting the exact size of the HumanoidRootPart is not accounting for the extra tolerance you set its position later on to in this line:

hrp.CFrame = CFrame.new(rootResult.Position) + Vector3.new(0, 5, 0) -- the tolerance.

So, I would suggest adding that same tolerance to the HumanoidRootPart’s size when you retrieve it:

local size = hrp.Size + Vector3.new(0, 5, 0) -- the tolerance.

Also, perhaps the player’s character is colliding with the ledge which is causing it to lose impulse? In that case, you can backing up the character a bit (like half stud should do it); I’m unsure this would work, though, mainly because I’m not at my PC right now so I can’t test anything.

Let me know how that goes.

2 Likes

Thank you, This made it much more responsive and easier to actually do!

1 Like

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