When Raycasting does the part in which the raycast begins get automatically ignored, if yes then is there a way to enable the detection of that part ?
No because the raycast doesn’t begin from a part. It begins at a position.
Casting
Once the origin and direction are determined, the ray is cast with theWorldRoot:Raycast()
function. This function also accepts an optionalRaycastParams
object which, in this sample, tells the ray to ignore (blacklist) the caster’s parent ( LaserCaster model) and all of its descendants.
Usually for me if a raycast starts inside a part, it doesn’t hit that part
As @QuackyWhackity said, if it starts within a part, it doesn’t hit that part.
A potential solution (not extraordinarily efficient) could be to racast backwards from the original raycast hit point, back to the origin. And determine if there’s a part near the initial starting point.
Though, if you are making some sort of weapon though, like a raycast gun, I just suggest starting the raycast from the head or making the gun can collide
Hey! So when using raycasting, nothing is automatically ignored which is why you must make an ignore list and make the part where the raycast is coming from ignored. Here is an example of using an ignore list when raycasting:
local raycastParams = RaycastParams.new()
local prompt = part:WaitForChild("ProximityPrompt")
raycastParams.FilterDescendantsInstances = {part,trees} - -here is your ignore list. In this case I'm ignoring the part and all the trees in my game.
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist -- Self explanitory. Just makes it so it eithers whitelists or blacklists the items in your ignorelist.
raycastParams.IgnoreWater = true -- Since my game has terrain, I want this to ignore water but this is optional.
local ray = workspace:Raycast( -- here we are creating the ray
part.Position, -- where it starts from
part.CFrame.UpVector * -1000, -- where it's pointing. In this case mine is pointing down
raycastParams -- passing through your parameters / ignore list
)
Alternatively, you can just do something like:
local ray = Ray.new(originPart, endPosition) -- origin part being the part you're raycasting from and endPosition being where you want the raycast to end
local hit, position = workspace:FindPartOnRayWithIgnoreList(ray,{originPart}) -- hit is just the part within the ray and position is the position of that part.
Hope this helps!