So lately, I’ve been using the FastCast module in order to test projectile-shooting NPCs. I got all the basic stuff working.
Anyways, an issue occurs where the visual bullet, when fired for long enough, starts to glitch out visually. However, everything seems to be working smoothly in server view.
Here is the video (DropBox Link):
Here is the script (regular script placed within the dummy model):
local rs = game:GetService("ReplicatedStorage")
local fastcast = require(rs.FastCastRedux)
local bullet = rs.NPCBullet
local caster = fastcast.new()
local dummy = script.Parent
local humanoidRootPart = dummy:WaitForChild("HumanoidRootPart")
local behavior = fastcast.newBehavior()
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {humanoidRootPart}
behavior.RaycastParams = params
behavior.AutoIgnoreContainer = true
behavior.CosmeticBulletTemplate = bullet
behavior.CosmeticBulletContainer = workspace.NPCProjectiles
behavior.MaxDistance = 100
caster.LengthChanged:Connect(function(ActiveCast, lastPoint, rayDir, displacement, segmentVelocity, cosmeticBulletObject)
local newpos = lastPoint + (rayDir * displacement)
cosmeticBulletObject.Position = newpos
end)
caster.RayHit:Connect(function(ActiveCast, RaycastResult, segmentVelocity, cosmeticBulletObject)
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 10
explosion.Position = RaycastResult.Position
explosion.Parent = workspace
game:GetService("Debris"):AddItem(explosion, 0.2)
cosmeticBulletObject:Destroy()
end)
local function shootProjectile()
local firePosition = humanoidRootPart.Position
local direction = (humanoidRootPart.CFrame.LookVector).unit
caster:Fire(firePosition, direction, 50, behavior)
end
local function shootEverySecond()
while true do
shootProjectile()
wait(1)
end
end
shootEverySecond()
I’m still trying to figure out the cause of this, maybe its a desync issue? I’m not too sure as of right now. Any insights would be appreciated.