Raycast from under a part

Hello! I want to raycast a ray starting from a part to 10 studs under the part. How do i do this? I’ve looked up guides and couldn’t find anything sorry. You might be saying, “Dank, you should know how to do this, you’ve been scripting for a long time!” Well, I’ve tried -upvector but it wasn’t as accurate as i had hoped.

local part = workspace.Part
local origin = part.Position -- the origin position we want to raycast from
local direction = Vector3.new(0, -10, 0) --the position we will want to cast our ray to
 What if the part is part of a bigger model and we don't want to hit the model with our ray? we blacklist the 
 descendants of that model!
 i'm only mentioning this because eventually, you'll want to ignore something when raycasting
local raycastParams = RaycastParams.new() -- construct a RaycastParams object that contains the parametres of our Raycast method
raycastParams.FilterDescendantsInstances = {part.Parent} -- part.Parent assumed to be a model
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
workspace:Raycast(origin, direction) -- or workspace:Raycast(origin, direction, raycastParams) if you include the commented code

Hi! Thanks for the solution! I actually found another solution since instead of raycasting I decided to use gettouchingparts to detect any parts that the part was touching. However, this knowledge is good to have so thanks for it anyways. Have a nice day!

1 Like