Is there a way to detect if a part is hit by a raycast?
you can do
local result: RaycastResult = workspace:Raycast(origin: vector3,direction: vector3) result.Instance
no the other way around
i mean like detecting if a part is hit by a raycast not if a raycast hits a part
umm i don’t think there is a way to do that. the only way i can think of is create your own raycast logic and use it every single part of your script that use raycast like setting attribute when a raycast it a part
You can detect if the part intersects with a raycast by using a whitelist with just the target part. If nothing returns as a result, the part is not being hit by the ray. Here’s what the code would look like:
-- create raycast parameters, note these can be reused if looped for the same part
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params:AddToFilter(part)
local result = workspace:Raycast(origin,direction,params)
local intersects = result ~= nil -- true if the raycast intersects the part, false if not
Hope this helps!
you would need to save what parts the ray hits by putting them into a table or changing an attribute on the part to true which then can be checked by other scripts