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.
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.