i’m trying to make a bullet casing system that doesn’t rely on roblox’s physics, but most of the time they just phase through objects
function module.casing(pos:Vector3, mdl:BasePart, shotgun:boolean)
local casing = mdl:Clone()
local firstbounce = false
local bounces = math.random(1,4)
local folder
if shotgun then
folder = script.casingsounds.shotgun
else
folder = script.casingsounds.metal
end
casing.Anchored = true
casing.Position = pos
casing.CanCollide = false; casing.CanQuery = false; casing.CanTouch = false
casing.Parent = workspace
local initvel = Vector3.new(math.random(-40,40)/100, math.random(50,70)/100, math.random(-40,40)/100)
local vel = initvel
local filter = RaycastParams.new()
filter.RespectCanCollide = true
for i,v in pairs(workspace:GetChildren()) do
if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") then
filter:AddToFilter(v:GetDescendants())
end
end
local poop
game:GetService("TweenService"):Create(casing, TweenInfo.new(6, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 2), {Transparency = 1}):Play()
game:GetService("Debris"):AddItem(casing, 8)
poop = game:GetService("RunService").Heartbeat:Connect(function()
local ray = workspace:Raycast(casing.Position, vel, filter)
if ray then
if bounces >= 1 then
bounces -= 1
casing.Position = ray.Position
casing.CFrame = CFrame.new(casing.Position, ray.Position + ray.Normal) * CFrame.Angles(math.rad(90),0,0)
vel = Vector3.new(ray.Normal.X, -vel.Y, ray.Normal.Z)*math.random(-100,100)/100
else
poop:Disconnect()
casing.CFrame = CFrame.new(ray.Position, ray.Position + ray.Normal) * CFrame.Angles(math.rad(90),0,0)
vel = Vector3.one*0
end
end
vel += Vector3.new(0, -.05, 0)
casing.Position += vel
end)
end