So I made a shell case effect that spawns a physical object when the player shoots. Though, if the player moves in a lot of directions, the casings may go through the gun and whatnot. How can I prevent this?
local function createVFX()
currentViewmodel = game.Workspace.Camera:FindFirstChildOfClass("Model") :: Model
if currentViewmodel then
local ejection = currentViewmodel:FindFirstChild("Bolt"):FindFirstChildOfClass("Attachment") :: Attachment
local casingClone = gunInfo["Casing Type"]:Clone()
local muzzle = currentViewmodel:FindFirstChild("Barrel"):FindFirstChildOfClass("Attachment") :: Attachment
local vfx_muzzleFlash = muzzle:FindFirstChildOfClass("ParticleEmitter") :: ParticleEmitter
local vfx_light = muzzle:FindFirstChildOfClass("PointLight") :: PointLight
vfx_muzzleFlash.Enabled = true
vfx_light.Enabled = true
task.wait(gunInfo["Fire Rate"])
vfx_muzzleFlash.Enabled = false
vfx_light.Enabled = false
casingClone.Anchored = false
casingClone.Transparency = 1
casingClone.Parent = game.Workspace.BulletCasings
casingClone.CFrame = ejection.WorldCFrame
casingClone.Rotation = Vector3.new(math.random(20, 180), math.random(20, 180), math.random(20, 180))
local rng = Random.new()
local mass = casingClone:GetMass()
local upVector = ejection.WorldCFrame.UpVector
local rightVector = ejection.WorldCFrame.RightVector
local desiredSpeed = upVector * rng:NextNumber(5, 10) + rightVector * rng:NextNumber(10, 15)
local impulse = mass * desiredSpeed --| Force = mass * acceleration
casingClone:ApplyImpulse(impulse)
task.wait(0.03)
casingClone.Transparency = 0
end
end