Hello! I’m working at my gun, however my game has lots of invisible and cancollide objects, and the ray detects the invisible objects and not the zombies sometimes.
I have a ideea, however I’m not sure how to make it. The ideea was to continue the ray from the point where it hit the invisible part, in the direction where the bullet should go, and repeat if there are more invisible parts. I don’t need any code for the Gun, only for the ray
There are a couple of ways. The way you mentioned is one of them. Alternatively, you can actually set the collision group of the Raycast to be different from the in invis parts by doing
local RaycastParameters = RaycastParams.new()
RaycastParameters.CollisipnGroup = "Zombie"
Or you can set the Raycast to only collide with the objects that you specifies or if ore object you do not want it to hit.
RaycastParameters.FilterType = Enum.CollisionFilterType.Whitelist
RaycastParameters.FilterDescendantInstances = {}-- Table of instances of Zombies
And the other one keeps raycasting. If the hit is nothing, return the result. If the hit is a invisible/cancollide off part, then add it to the Ignore table and continue. If the result is a normal part, return the result.
Great that you found a solution, but I’d recommend you to use raycast collision groupings instead. While the performance difference is minimal, using collision filtering would still require less script activity anyway.