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.