I want it so that in my game, when you shoot a zombie, the bullet will go through 2-3 zombies before stopping, I’m using ray casting and I can’t find a good way to add this feature since a ray stops when it hits a part. If anyone has any ideas or has experienced what I’m trying to implement then please help me. Thank you.
I’ve actually seen this idea demonstrated before. Basically, for each ray that hits a part, recurse the method that casts rays with the hit instance added to a table that’ll be used as the ignore instances table. Keep doing this until X rays have been made or until no more parts are found.
Example:
local range = 10 --//Length of ray
local ignore_table = {}
local ray_params = RayParams.new()
ray_params.FilterType = Enum.RaycastFilterType.Blacklist
function Cast_Ray(origin, direction)
ray_params.FilterDescendantsInstances = ignore_table
local result = workspace:Raycast(origin, direction*range, ray_params)
if result then
if table.result.Instance.Parent == "Workspace" then
table.insert(ignore_table, result.Instance)
else
table.insert(ignore_table, result.Instance.Parent)
end
Cast_Ray(result.Position, direction)
else
ignore_table = {}
end
end
--//Call Cast_Ray method with a given origin position and direction.
Untested, but this logic should be roughly what you’re looking for.
1 Like