I’m trying to make a ledge grab, but when I did make it, it does not look very smooth. I’m not sure how I’m supposed to make this smother than it isn’t, and I’m trying to figure out how.
You can look at the ledge grab here
Here’s the script
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local root = char.PrimaryPart
local origion = root.Position
local direction = root.CFrame.LookVector * 1.5
local vizual = Instance.new("Part", workspace)
vizual.Anchored = true
vizual.CFrame = root.CFrame
vizual.CanCollide = false
vizual.Name = "Visualizer"
vizual.BrickColor = BrickColor.random()
vizual.Transparency = .25
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.IgnoreWater = true
params.FilterDescendantsInstances = {char, vizual}
function nearestNormalId(part, direction)
local maxDot, maxNormal = 0, nil --Exclude results <= 0
for _, normalId in ipairs(Enum.NormalId:GetEnumItems()) do
local normal = part.CFrame:VectorToWorldSpace(Vector3.fromNormalId(normalId))
local dot = normal:Dot(direction) --Greater the more similar the vectors are
if dot > 0 and dot > maxDot then
maxDot = dot
maxNormal = normal
end
end
return maxNormal
end
game:GetService("RunService").RenderStepped:Connect(function()
local midpoint = origion + direction/2
origion = root.CFrame.Position direction = root.CFrame.LookVector * 1.5
vizual.Size = Vector3.new(1, 1, direction.Magnitude)
vizual.CFrame = CFrame.new(midpoint, origion)
local rayPart = Instance.new("Part")
local ray = workspace:Raycast(origion, direction, params) if ray then
rayPart.Position = ray.Position
if ray.Instance ~= nil and ray.Instance.Name == "ledgePart" and root.Position.Y < ray.Instance.Position.Y then
local normal = nearestNormalId(ray.Instance, direction)
if normal == Vector3.new(0, 0, -1) then
task.wait(.2)
root.Anchored = true
root.CFrame = rayPart.CFrame - Vector3.new(0, 2.5, -2)
task.wait(2)
root.Anchored = false
elseif normal == Vector3.new(0, 0, 1) then
task.wait(.75)
root.CFrame = ray.Instance.CFrame * CFrame.Angles(0, math.rad(-180), 0) - Vector3.new(0, 2.5, 2)
task.wait(2)
root.Anchored = false
elseif normal == Vector3.new(1, 0, 0) then
task.wait(.75)
root.CFrame = ray.Instance.CFrame * CFrame.Angles(0, math.rad(-90), 0) - Vector3.new(2, 2.5, 0)
task.wait(2)
root.Anchored = false
elseif normal == Vector3.new(-1, 0, 0) then
task.wait(.75)
root.CFrame = ray.Instance.CFrame * CFrame.Angles(0, math.rad(90), 0) - Vector3.new(-2, 2.5, 0)
task.wait(2)
root.Anchored = false
end
end
end
end)
-- CFrame.Angles(0, math.rad(-90), 0)