Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Which way is the best way to make ledge grabbing?

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

✓ Accepted answer

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.

2 comments

0

Thank you for explaining!

0

Thank you for explaining!

This discussion is preserved as it was. New answers, comments, and votes are closed.