Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Which way is the best way to make ledge grabbing?

Asked by
Qariter 110
4 years ago

I need some confirmations here. Do i use raycasting or do i use some complex vector math? I want to figure out how to get the closest edge of a part from a player's magnitude.

All help is appreciated, thank you.

1 answer

Log in to vote
1
Answered by
WBlair 35
4 years ago

You can use 2 raycasts, one where the humanoid rootpart is (pointing where the humanoid rootpart is looking) and another at the humanoid rootpart's position but 1.5 studs up (the "heads" position). The one on the humanoid rootpart detects if there's a part and the one on the "head" detects if there is no part. This is a very easy way to detect the top of a part.

local rayDetectPart =Ray.new(char.HumanoidRootPart.Position,char.HumanoidRootPart.CFrame.LookVector*2) --2 studs in front of the player
local hit,point,normal =workspace:FindPartOnRay(rayDetectPart, char)

local rayNoDetectPart =Ray.new(char.HumanoidRootPart.CFrame+Vector3.new(0,1.5,0),char.HumanoidRootPart.CFrame.LookVector*2)
local nohit,nopoint,nonormal =workspace:FindPartOnRay(rayNoDetectPart, char)

if hit and not nohit then
initiategrab()
end

Very lazily made but it takes very little load on a computer's CPU and gets the job done.

0
Thank you for explaining! Qariter 110 — 4y
0
Thank you for explaining! Qariter 110 — 4y
Ad

Answer this question