I’m using fast cast for arrows, but it keeps getting stuck on zones that I made with zoneplus.
Zoneplus requires CanQuery to be turned on so that it can check if people are in the zone.
But the fastcast raycast arrows keep getting stuck on the Zone part.
The Zone part has CanCollide turned off, but CanQuery turned on so it can find players.
I turned “RespectCanCollide” on for the Arrow raycast but it still hits the zone part even though the zone part’s CanCollide is turned off.
As you can see in this image, the zone part’s cancollide is turned off, but the canquery is turned on so it can find players, but players can go into the zone.
Arrow raycasts via fastcast get stuck on it however.
In the RaycastParams below, I turned RespectCanCollide to true.
But it still gets stuck on the zone part despite it being non-collidable.
Is there a way to make the raycast ignore canquery entirely?
So that the zone can find players, but arrow raycasts can still go through.
I tried changing the collisiongroup of the zone to ignore arrows, but I got this error from ZonePlus instead: Zone parts must belong to the ‘Default’ (0) CollisionGroup!
Thanks for the idea, I tried that just now by making a table, but the arrows still got stuck for some reason
local boatzones = {}
for _, v in pairs(workspace.NPC:GetChildren()) do
if v:FindFirstChild("ShipHealth") ~= nil then
if v.ShipHealth.Value > 0 and v:FindFirstChild("Zone") ~= nil then
table.insert(boatzones, v.Zone)
end
end
end
workspace.NPC.ChildAdded:Connect(function(v)
if v:FindFirstChild("ShipHealth") ~= nil then
if v.ShipHealth.Value > 0 and v:FindFirstChild("Zone") ~= nil then
table.insert(boatzones, v.Zone)
end
end
end)
workspace.NPC.ChildRemoved:Connect(function(v)
if v:FindFirstChild("ShipHealth") ~= nil then
if table.find(boatzones, v.Zone) then
table.remove(boatzones, table.find(boatzones, v.Zone))
end
end
end)
local caster = FastCast.new()
local castParams = RaycastParams.new()
castParams.CollisionGroup = "Arrows"
castParams.FilterDescendantsInstances = {c, boatzones}
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = true
castParams.RespectCanCollide = true
local bulletCache = PartCache.new(bulletTemplate, 10, bulletsFolder)
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -75, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletProvider = bulletCache
When you write your event signal listeners, it will insert the object into the table. Since lua interprets line by line and internally your raycast filtered descendants are stored into memory as is, there’s a possible edge case where your table is not including added instances. You need to update the filter when a new instance is inserted into the table, whichever method works for you.
It worked, thanks!
I had to go and update the table to filter descendants every time the arrow fires.
local function fire(player, mousePosition)
if player.Character.ToolEquipped.Value ~= script.Parent then
return
end
Player = player
firePoint = player.Character.RightHand.FirePoint
if tool.Parent:IsA("Backpack") then return end
if ammoLeft > 0 and not reloading and Arrows.Value > 0 then
script.Parent.Main.Fire:Play()
castParams.FilterDescendantsInstances = {c, boatzones}
castBehavior.RaycastParams = castParams
local origin = firePoint.WorldPosition
local direction = (mousePosition - origin).Unit
caster:Fire(origin, direction, 300, castBehavior)
Arrows.Value = Arrows.Value - 1
ammoLeft -= 1
else
reload()
end
end
That works fine, if you would like to further improve it, you can determine where it is necessary to update the filter. When you call the fire function, does it always need to update the filter, or does it only need to when a new instance is added into the workspace? That is your call to make, but I suggest reducing script usage by keeping it as minimal as possible.