local function q(q,y,K,b,d,c,E,j,z,m,p,P,i,O,a)PrintDebug("\067\097\115\116 \115\105\109\117\108\097\116\105\111\110 \114\101\113\117\101\115\116\101\100\046")if type(K)=="\110\117\109\098\101\114"then K=y.Unit*K end local I=a~=nil and a.penetrationDepth or 0 local C=a~=nil and a.penetrationAmount or 0 local x=p or Vector3.new()local g=y.Magnitude local X=y.Unit local A=(X+K).Unit local s=A*K.Magnitude local M=0 local H=0 local l=q local G={}local u=false local R=false local W=z local B=b local function S(y,K)PrintDebug("\067\097\115\116\105\110\103 \102\111\114 \102\114\097\109\101\046")M=M+y local p=K or GetPositionAtTime(M,q,s,x)local X=p-l local A=GetVelocityAtTime(M,s,x)local W=(X.Unit*A.Magnitude)*y local B,o,V,v=b(l,W,z,m)local Y=(o-l).Magnitude d:Fire(q,l,W.Unit,Y,A,j,P,i,O)local Q=nil if y>0 then Q=DbgVisualizeSegment(CFrame.new(l,l+W),Y)end if B and B~=j then local y=tick()local K=W.Unit local d=B.Size.Magnitude*K local P,i,x,g=CastWithWhitelist(o+d,-d,{B},m)local X=(i-o).Magnitude if a~=nil and(a.penetrationType=="\087\097\108\108\080\101\110\101\116\114\097\116\105\111\110"and(a.canPenetrateFunction~=nil and I>X)or a.penetrationType=="\072\117\109\097\110\111\105\100\080\101\110\101\116\114\097\116\105\111\110"and(a.canPenetrateHumanoidFunction~=nil and C>0))then if u then error("\069\082\082\079\082\058 \084\104\101 \108\097\116\101\115\116 \099\097\108\108 \116\111 \099\097\110\080\101\110\101\116\114\097\116\101\070\117\110\099\116\105\111\110\047\099\097\110\080\101\110\101\116\114\097\116\101\072\117\109\097\110\111\105\100\070\117\110\099\116\105\111\110 \116\111\111\107 \116\111\111 \108\111\110\103 \116\111 \099\111\109\112\108\101\116\101\033 \084\104\105\115 \099\097\115\116 \105\115 \103\111\105\110\103 \116\111 \115\117\102\102\101\114 \100\101\115\121\110\099\115 \119\104\105\099\104 \087\073\076\076 \099\097\117\115\101 \117\110\101\120\112\101\099\116\101\100 \098\101\104\097\118\105\111\114 \097\110\100 \101\114\114\111\114\115\046")end u=true R=false end if a==nil or a~=nil and(a.penetrationType=="\087\097\108\108\080\101\110\101\116\114\097\116\105\111\110"and I<X or a.penetrationType=="\072\117\109\097\110\111\105\100\080\101\110\101\116\114\097\116\105\111\110"and(a.canPenetrateHumanoidFunction(q,W.Unit,B,o,V,v,A,C,O)==false or C<=0))then PrintDebug("\080\101\110\101\116\114\097\116\105\110\103 \100\097\116\097 \105\115 \110\105\108 \111\114 \112\101\110\101\116\114\097\116\105\111\110\080\111\119\101\114 \105\115 \108\111\119\101\114 \116\104\097\110 \100\105\115\116\047\112\101\110\101\116\114\097\116\105\111\110\067\111\117\110\116 \105\115 \097\116 \048\046 \069\110\100\105\110\103 \099\097\115\116 \097\110\100 \102\105\114\105\110\103 \082\097\121\072\105\116\046")u=false RemoveList[G]=true c:Fire(q,W.Unit,B,o,V,v,A,j,O)DbgVisualizeHit(CFrame.new(o),Color3.new(.2,1,.5))return else if Q~=nil then Q.Color3=Color3.new(.4,.05,.05)end DbgVisualizeHit(CFrame.new(o),Color3.new(1,.2,.2))PrintDebug("\080\101\110\101\116\114\097\116\105\110\103 \114\101\116\117\114\110\101\100 \'\112\101\110\101\116\114\097\116\101\100\072\117\109\097\110\111\105\100\' \111\114 \'\112\101\110\101\116\114\097\116\101\100\079\098\106\101\099\116\'\047\084\082\085\069 \116\111 \112\101\110\101\116\114\097\116\101 \116\104\105\115 \104\105\116\046 \080\114\111\099\101\115\115\105\110\103\046\046\046")u=false if a.penetrationType=="\087\097\108\108\080\101\110\101\116\114\097\116\105\111\110"then local y=a~=nil and a.canPenetrateFunction(q,W.Unit,B,o,V,v,A,O)if b==CastWithWhitelist then if y=="\112\101\110\101\116\114\097\116\101\100\072\117\109\097\110\111\105\100"and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0)or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 then if P and FastCast.RayExit then E:Fire(o+d,-d,P,i,x,g,A,O)DbgVisualizeHit(CFrame.new(i),Color3.fromRGB(13,105,172))end local q=B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")table.removeObject(z,q.Parent)local y=1-(X/I)/1.1 I=I*y PrintDebug("\087\104\105\116\101\108\105\115\116 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \114\101\109\111\118\101\100 "..(tostring(q.Parent).." \102\114\111\109 \116\104\101 \119\104\105\116\101\108\105\115\116\046"))elseif y=="\112\101\110\101\116\114\097\116\101\100\079\098\106\101\099\116"then if P and FastCast.RayExit then E:Fire(o+d,-d,P,i,x,g,A,O)DbgVisualizeHit(CFrame.new(i),Color3.fromRGB(13,105,172))end table.removeObject(z,B)local q=1-(X/I)/1.1 I=I*q PrintDebug("\087\104\105\116\101\108\105\115\116 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \114\101\109\111\118\101\100 "..(tostring(B).." \102\114\111\109 \116\104\101 \119\104\105\116\101\108\105\115\116\046"))end elseif b==CastWithBlacklistAndNoHumPenetration then if y=="\112\101\110\101\116\114\097\116\101\100\072\117\109\097\110\111\105\100"and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0)or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 then if P and FastCast.RayExit then E:Fire(o+d,-d,P,i,x,g,A,O)DbgVisualizeHit(CFrame.new(i),Color3.fromRGB(13,105,172))end local q=B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")table.insert(z,q.Parent)local y=1-(X/I)/1.1 I=I*y PrintDebug("\066\108\097\099\107\108\105\115\116 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \097\100\100\101\100 "..(tostring(q.Parent).." \116\111 \116\104\101 \098\108\097\099\107\108\105\115\116\046"))elseif y=="\112\101\110\101\116\114\097\116\101\100\079\098\106\101\099\116"then if P and FastCast.RayExit then E:Fire(o+d,-d,P,i,x,g,A,O)DbgVisualizeHit(CFrame.new(i),Color3.fromRGB(13,105,172))end table.insert(z,B)local q=1-(X/I)/1.1 I=I*q PrintDebug("\066\108\097\099\107\108\105\115\116 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \097\100\100\101\100 "..(tostring(B).." \116\111 \116\104\101 \098\108\097\099\107\108\105\115\116\046"))end else b=CastWithBlacklistAndNoHumPenetration z=z:GetDescendants()if y=="\112\101\110\101\116\114\097\116\101\100\072\117\109\097\110\111\105\100"and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0)or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 then if P and FastCast.RayExit then E:Fire(o+d,-d,P,i,x,g,A,O)DbgVisualizeHit(CFrame.new(i),Color3.fromRGB(13,105,172))end local q=B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")table.insert(z,q.Parent)local y=1-(X/I)/1.1 I=I*y PrintDebug("\083\116\111\099\107 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \116\114\097\110\115\102\111\114\109\101\100 \099\097\115\116 \105\110\116\111 \098\108\097\099\107\108\105\115\116 \099\097\115\116 \097\110\100 \097\100\100\101\100 "..(tostring(q.Parent).." \116\111 \116\104\101 \098\108\097\099\107\108\105\115\116\046"))elseif y=="\112\101\110\101\116\114\097\116\101\100\079\098\106\101\099\116"then if P and FastCast.RayExit then E:Fire(o+d,-d,P,i,x,g,A,O)DbgVisualizeHit(CFrame.new(i),Color3.fromRGB(13,105,172))end table.insert(z,B)local q=1-(X/I)/1.1 I=I*q PrintDebug("\083\116\111\099\107 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \116\114\097\110\115\102\111\114\109\101\100 \099\097\115\116 \105\110\116\111 \098\108\097\099\107\108\105\115\116 \099\097\115\116 \097\110\100 \097\100\100\101\100 "..(tostring(B).." \116\111 \116\104\101 \098\108\097\099\107\108\105\115\116\046"))end end elseif a.penetrationType=="\072\117\109\097\110\111\105\100\080\101\110\101\116\114\097\116\105\111\110"then if b==CastWithWhitelist then if B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 then R=true local q=B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")table.removeObject(z,q.Parent)PrintDebug("\087\104\105\116\101\108\105\115\116 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \114\101\109\111\118\101\100 "..(tostring(q.Parent).." \102\114\111\109 \116\104\101 \119\104\105\116\101\108\105\115\116\046"))else R=false table.removeObject(z,B)PrintDebug("\087\104\105\116\101\108\105\115\116 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \114\101\109\111\118\101\100 "..(tostring(B).." \102\114\111\109 \116\104\101 \119\104\105\116\101\108\105\115\116\046"))end elseif b==CastWithBlacklist then if B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 then R=true local q=B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")table.insert(z,q.Parent)PrintDebug("\066\108\097\099\107\108\105\115\116 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \097\100\100\101\100 "..(tostring(q.Parent).." \116\111 \116\104\101 \098\108\097\099\107\108\105\115\116\046"))else R=false table.insert(z,B)PrintDebug("\066\108\097\099\107\108\105\115\116 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \097\100\100\101\100 "..(tostring(B).." \116\111 \116\104\101 \098\108\097\099\107\108\105\115\116\046"))end else b=CastWithBlacklist z=z:GetDescendants()if B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")and(B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).Health>0 then R=true local q=B.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")or B.Parent.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")table.insert(z,q.Parent)PrintDebug("\083\116\111\099\107 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \116\114\097\110\115\102\111\114\109\101\100 \099\097\115\116 \105\110\116\111 \098\108\097\099\107\108\105\115\116 \099\097\115\116 \097\110\100 \097\100\100\101\100 "..(tostring(q.Parent).." \116\111 \116\104\101 \098\108\097\099\107\108\105\115\116\046"))else R=false table.insert(z,B)PrintDebug("\083\116\111\099\107 \099\097\115\116 \100\101\116\101\099\116\101\100\044 \116\114\097\110\115\102\111\114\109\101\100 \099\097\115\116 \105\110\116\111 \098\108\097\099\107\108\105\115\116 \099\097\115\116 \097\110\100 \097\100\100\101\100 "..(tostring(B).." \116\111 \116\104\101 \098\108\097\099\107\108\105\115\116\046"))end end end PrintDebug("\082\101\099\097\115\116\105\110\103 \102\111\114 \112\101\110\101\116\114\097\116\105\111\110\046\046\046")S(0,p)l=o if a~=nil then if a.penetrationType~="\087\097\108\108\080\101\110\101\116\114\097\116\105\111\110"then if R then C=B and C-1 or 0 PrintDebug("\112\101\110\101\116\114\097\116\105\111\110\067\111\117\110\116 \105\115 \114\101\100\117\099\101\100 \116\111\046\046\046 "..(C.." \102\111\114 \104\105\116\116\105\110\103 \104\117\109\097\110\111\105\100\046"))else PrintDebug("\112\101\110\101\116\114\097\116\105\111\110\067\111\117\110\116 \105\115 \110\111\116 \114\101\100\117\099\101\100 \102\111\114 \110\111\116 \104\105\116\116\105\110\103 \104\117\109\097\110\111\105\100 \040\111\114 \116\104\101 \104\117\109\097\110\111\105\100 \100\105\101\100\041\046")end else PrintDebug("\068\073\083\084\065\078\067\069\058 "..(X.." \115\116\117\100\115"))PrintDebug("\067\085\082\082\069\078\084 \080\069\078\069\084\082\065\084\073\079\078 \068\069\080\084\072\058 "..(I.." \115\116\117\100\115"))end end return end end l=o H=H+Y if H>g then RemoveList[G]=true c:Fire(q,W.Unit,nil,l,nil,nil,Vector3.new(),j,O)end end function G.Update(q)S(q)end if RunService:IsClient()then spawn(function()Projectiles[G]=true end)else Thread:Spawn(function()Projectiles[G]=true end)end end local function y(y,K,b,d,c,E,j,z,m,p,P,i,O,a)MandateType(K,"\086\101\099\116\111\114\051","\111\114\105\103\105\110")MandateType(b,"\086\101\099\116\111\114\051","\100\105\114\101\099\116\105\111\110\087\105\116\104\077\097\103\110\105\116\117\100\101")assert(typeof(d)=="\086\101\099\116\111\114\051"or typeof(d)=="\110\117\109\098\101\114",ERR_INVALID_TYPE:format("\118\101\108\111\099\105\116\121","\086\097\114\105\097\110\116\060\086\101\099\116\111\114\051\044 \110\117\109\098\101\114\062",typeof(d)))MandateType(c,"\073\110\115\116\097\110\099\101","\099\111\115\109\101\116\105\099\066\117\108\108\101\116\079\098\106\101\099\116",true)MandateType(E,"\073\110\115\116\097\110\099\101","\105\103\110\111\114\101\068\101\115\099\101\110\100\097\110\116\115\073\110\115\116\097\110\099\101",true)MandateType(j,"\098\111\111\108\101\097\110","\105\103\110\111\114\101\087\097\116\101\114",true)MandateType(z,"\086\101\099\116\111\114\051","\098\117\108\108\101\116\065\099\099\101\108\101\114\097\116\105\111\110",true)MandateType(i,"\116\097\098\108\101","\108\105\115\116",true)MandateType(a,"\116\097\098\108\101","\112\101\110\101\116\114\097\116\105\111\110\068\097\116\097",true)local I=Cast local C=E if i~=nil then C=i if O then I=CastWithWhitelist else I=a and(a.penetrationType~="\087\097\108\108\080\101\110\101\116\114\097\116\105\111\110"and CastWithBlacklist)or CastWithBlacklistAndNoHumPenetration or CastWithBlacklistAndNoHumPenetration end end q(K,b,d,I,y.LengthChanged,y.RayHit,y.RayExited,c,C,j,z,m,p,P,a)end

local function SimulateCast(origin, direction, velocity, castFunction, lengthChangedEvent, rayHitEvent, rayExitedEvent, cosmeticBulletObject, listOrIgnoreDescendantsInstance, ignoreWater, bulletAcceleration, bulletData, whizData, hitData, penetrationData)
	PrintDebug("Cast simulation requested.")
	if type(velocity) == "number" then
		velocity = direction.Unit * velocity
	end
	
	local penetrationPower = penetrationData ~= nil and penetrationData.penetrationDepth or 0
	local penetrationCount = penetrationData ~= nil and penetrationData.penetrationAmount or 0
	local bulletAcceleration = bulletAcceleration or Vector3.new() -- Fix bug reported by Spooce: Failing to pass in the bulletAcceleration parameter throws an error, so add a fallback of Vector3.new()
	local distance = direction.Magnitude -- This will be a unit vector multiplied by the maximum distance.
	local normalizedDir = direction.Unit
	local upgradedDir = (normalizedDir + velocity).Unit -- This rotates the direction of the bullet by the initial velocity, allowing 3D velocity to occur in the first place.
	local initialVelocity = upgradedDir * velocity.Magnitude
	
	local totalDelta = 0
	local distanceTravelled = 0
	local lastPoint = origin
	
	local self = {}
	local isRunningPenetration = false
	local didHitHumanoid = false
	local originalList = listOrIgnoreDescendantsInstance
	local originalCastFunction = castFunction
	
	local function Fire(delta, customAt)
		PrintDebug("Casting for frame.")
		totalDelta = totalDelta + delta
		local at = customAt or GetPositionAtTime(totalDelta, origin, initialVelocity, bulletAcceleration)
		local totalDisplacement = (at - lastPoint) -- This is the displacement from where the ray was on the last from to where the ray is now.
		
		-- NEW BEHAVIOR:
		-- Displacement needs to define velocity. The reason peoples' casts were going crazy was because on the line below I used to multiply by velocity.Magnitude
		-- Okay, cool, so that's effectively the initial velocity. Now say we're at the top of an arc in a physics cast. Bullet sure isn't going the same speed!
		-- We need to recalculate velocity based on displacement, NOT use the defined value.
		-- How I missed this is beyond me.
		-- Bonus ducks: This also allows me to implement GFink's request (see https://devforum.roblox.com/t/making-a-combat-game-with-ranged-weapons-fastcast-may-be-the-module-for-you/133474/282?u=etithespirit)
		
		local segmentVelocity = GetVelocityAtTime(totalDelta, initialVelocity, bulletAcceleration) 
		-- local rayDir = totalDisplacement.Unit * segmentVelocity.Magnitude * delta -- Direction of the ray is the direction from last to now * the velocity * deltaTime
		local rayDir = totalDisplacement.Unit * segmentVelocity.Magnitude * delta
		local hit, point, normal, material = castFunction(lastPoint, rayDir, listOrIgnoreDescendantsInstance, ignoreWater)
		
		local rayDisplacement = (point - lastPoint).Magnitude
		-- For clarity -- totalDisplacement is how far the ray would have traveled if it hit nothing,
		-- and rayDisplacement is how far the ray really traveled (which will be identical to totalDisplacement if it did indeed hit nothing)
		
		lengthChangedEvent:Fire(origin, lastPoint, rayDir.Unit, rayDisplacement, segmentVelocity, cosmeticBulletObject, bulletData, whizData, hitData)
		
		local rayVisualization = nil
		if (delta > 0) then
			rayVisualization = DbgVisualizeSegment(CFrame.new(lastPoint, lastPoint + rayDir), rayDisplacement)
		end
		
		if hit and hit ~= cosmeticBulletObject then
			local start = tick()
            local unit = rayDir.Unit
            local maxExtent = hit.Size.Magnitude * unit
            local exitHit, exitPoint, exitNormal, exitMaterial = CastWithWhitelist(point + maxExtent, -maxExtent, {hit}, ignoreWater)
            --local diff = exitPoint - point
            --local dist = Vector3.new():Dot(unit, diff)
			local dist = (exitPoint - point).Magnitude
			
			-- SANITY CHECK: Don't allow the user to yield or run otherwise extensive code that takes longer than one frame/heartbeat to execute.
			if (penetrationData ~= nil) and (penetrationData.penetrationType == "WallPenetration" and ((penetrationData.canPenetrateFunction ~= nil) and (penetrationPower > dist)) or (penetrationData.penetrationType == "HumanoidPenetration" and ((penetrationData.canPenetrateHumanoidFunction ~= nil) and (penetrationCount > 0)))) then
				if (isRunningPenetration) then
					error("ERROR: The latest call to canPenetrateFunction/canPenetrateHumanoidFunction took too long to complete! This cast is going to suffer desyncs which WILL cause unexpected behavior and errors.")
					-- Use error. This should absolutely abort the cast.
				end
				isRunningPenetration = true
				didHitHumanoid = false
			end
			
			if penetrationData == nil or (penetrationData ~= nil and ((penetrationData.penetrationType == "WallPenetration" and (penetrationPower < dist)) or (penetrationData.penetrationType == "HumanoidPenetration" and ((penetrationData.canPenetrateHumanoidFunction(origin, rayDir.Unit, hit, point, normal, material, segmentVelocity, penetrationCount, hitData) == false) or (penetrationCount <= 0))))) then
				PrintDebug("Penetrating data is nil or penetrationPower is lower than dist/penetrationCount is at 0. Ending cast and firing RayHit.")
				isRunningPenetration = false
				-- Penetrate function is nil, or it's not nil and it returned false (we cannot penetrate this object).
				-- Hit.
				
				RemoveList[self] = true
				rayHitEvent:Fire(origin, rayDir.Unit, hit, point, normal, material, segmentVelocity, cosmeticBulletObject, hitData)
				DbgVisualizeHit(CFrame.new(point), Color3.new(0.2, 1, 0.5))
				return
			else
				if rayVisualization ~= nil then
					rayVisualization.Color3 = Color3.new(0.4, 0.05, 0.05) -- Turn it red to signify that the cast was scrapped.
				end
				DbgVisualizeHit(CFrame.new(point), Color3.new(1, 0.2, 0.2))
				
				PrintDebug("Penetrating returned 'penetratedHumanoid' or 'penetratedObject'/TRUE to penetrate this hit. Processing...")
				isRunningPenetration = false
				-- Nope! We want to penetrate this part.				
				-- Now this is gonna be DISGUSTING. 
				-- We need to run this until we fufill that lost distance, so if some guy decides to layer up like 10 parts right next to eachother, we need to handle all of those in a single frame
				-- The only way to do this isn't particularly pretty but it needs to be quick.
				if penetrationData.penetrationType == "WallPenetration" then
					local penetrationType = penetrationData ~= nil and penetrationData.canPenetrateFunction(origin, rayDir.Unit, hit, point, normal, material, segmentVelocity, hitData)		
					if (castFunction == CastWithWhitelist) then
						-- User is using whitelist. We need to pull this from their list.
						-- n.b. this function is offered by the sandboxed table system. It's not stock.
						if penetrationType == "penetratedHumanoid" and (hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent:FindFirstChildOfClass("Humanoid").Health > 0) or (hit.Parent.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Parent:FindFirstChildOfClass("Humanoid").Health > 0) then
							if exitHit and FastCast.RayExit then
								rayExitedEvent:Fire(point + maxExtent, -maxExtent, exitHit, exitPoint, exitNormal, exitMaterial, segmentVelocity, hitData)
								DbgVisualizeHit(CFrame.new(exitPoint), Color3.fromRGB(13, 105, 172))
							end
							local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") or hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
							table.removeObject(listOrIgnoreDescendantsInstance, humanoid.Parent)
							--penetrationPower = penetrationPower
							local toReduce = 1-((dist/penetrationPower/1.1))
							penetrationPower = penetrationPower * toReduce
							PrintDebug("Whitelist cast detected, removed " .. tostring(humanoid.Parent) .. " from the whitelist.")
						elseif penetrationType == "penetratedObject" then
							if exitHit and FastCast.RayExit then
								rayExitedEvent:Fire(point + maxExtent, -maxExtent, exitHit, exitPoint, exitNormal, exitMaterial, segmentVelocity, hitData)
								DbgVisualizeHit(CFrame.new(exitPoint), Color3.fromRGB(13, 105, 172))
							end
							table.removeObject(listOrIgnoreDescendantsInstance, hit)
							--penetrationPower = penetrationPower - dist
							local toReduce = 1-((dist/penetrationPower/1.1))
							penetrationPower = penetrationPower * toReduce
							PrintDebug("Whitelist cast detected, removed " .. tostring(hit) .. " from the whitelist.")
						end
					elseif (castFunction == CastWithBlacklistAndNoHumPenetration) then
						if penetrationType == "penetratedHumanoid" and (hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent:FindFirstChildOfClass("Humanoid").Health > 0) or (hit.Parent.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Parent:FindFirstChildOfClass("Humanoid").Health > 0) then
							if exitHit and FastCast.RayExit then
								rayExitedEvent:Fire(point + maxExtent, -maxExtent, exitHit, exitPoint, exitNormal, exitMaterial, segmentVelocity, hitData)
								DbgVisualizeHit(CFrame.new(exitPoint), Color3.fromRGB(13, 105, 172))
							end
							local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") or hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
							table.insert(listOrIgnoreDescendantsInstance, humanoid.Parent)
							--penetrationPower = penetrationPower
							local toReduce = 1-((dist/penetrationPower/1.1))
							penetrationPower = penetrationPower * toReduce
							PrintDebug("Blacklist cast detected, added " .. tostring(humanoid.Parent) .. " to the blacklist.")
						elseif penetrationType == "penetratedObject" then
							if exitHit and FastCast.RayExit then
								rayExitedEvent:Fire(point + maxExtent, -maxExtent, exitHit, exitPoint, exitNormal, exitMaterial, segmentVelocity, hitData)
								DbgVisualizeHit(CFrame.new(exitPoint), Color3.fromRGB(13, 105, 172))
							end
							table.insert(listOrIgnoreDescendantsInstance, hit)
							--penetrationPower = penetrationPower - dist
							local toReduce = 1-((dist/penetrationPower/1.1))
							penetrationPower = penetrationPower * toReduce
							PrintDebug("Blacklist cast detected, added " .. tostring(hit) .. " to the blacklist.")	
						end
					else
						-- This is where things get finnicky.
						-- We can't reparent the object. If we do this, we risk altering behavior of the developer's game which has undesirable effects.
						-- We need to swap cast functions on the fly here. This is gonna get NASTY. Oh well. It should only happen once under this new behavior.
						castFunction = CastWithBlacklistAndNoHumPenetration
						listOrIgnoreDescendantsInstance = listOrIgnoreDescendantsInstance:GetDescendants()	
						if penetrationType == "penetratedHumanoid" and (hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent:FindFirstChildOfClass("Humanoid").Health > 0) or (hit.Parent.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Parent:FindFirstChildOfClass("Humanoid").Health > 0) then
							if exitHit and FastCast.RayExit then
								rayExitedEvent:Fire(point + maxExtent, -maxExtent, exitHit, exitPoint, exitNormal, exitMaterial, segmentVelocity, hitData)
								DbgVisualizeHit(CFrame.new(exitPoint), Color3.fromRGB(13, 105, 172))
							end
							local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") or hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
							table.insert(listOrIgnoreDescendantsInstance, humanoid.Parent)
							--penetrationPower = penetrationPower
							local toReduce = 1-((dist/penetrationPower/1.1))
							penetrationPower = penetrationPower * toReduce
							PrintDebug("Stock cast detected, transformed cast into blacklist cast and added " .. tostring(humanoid.Parent) .. " to the blacklist.")
						elseif penetrationType == "penetratedObject" then
							if exitHit and FastCast.RayExit then
								rayExitedEvent:Fire(point + maxExtent, -maxExtent, exitHit, exitPoint, exitNormal, exitMaterial, segmentVelocity, hitData)
								DbgVisualizeHit(CFrame.new(exitPoint), Color3.fromRGB(13, 105, 172))
							end
							table.insert(listOrIgnoreDescendantsInstance, hit)
							--penetrationPower = penetrationPower - dist
							local toReduce = 1-((dist/penetrationPower/1.1))
							penetrationPower = penetrationPower * toReduce
							PrintDebug("Stock cast detected, transformed cast into blacklist cast and added " .. tostring(hit) .. " to the blacklist.")						
						end				
					end
				elseif penetrationData.penetrationType == "HumanoidPenetration" then
					if (castFunction == CastWithWhitelist) then
						-- User is using whitelist. We need to pull this from their list.
						-- n.b. this function is offered by the sandboxed table system. It's not stock.
						if (hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent:FindFirstChildOfClass("Humanoid").Health > 0) or (hit.Parent.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Parent:FindFirstChildOfClass("Humanoid").Health > 0) then
							didHitHumanoid = true
							local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") or hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
							table.removeObject(listOrIgnoreDescendantsInstance, humanoid.Parent)
							PrintDebug("Whitelist cast detected, removed " .. tostring(humanoid.Parent) .. " from the whitelist.")
						else
							didHitHumanoid = false
							table.removeObject(listOrIgnoreDescendantsInstance, hit)
							PrintDebug("Whitelist cast detected, removed " .. tostring(hit) .. " from the whitelist.")
						end
					elseif (castFunction == CastWithBlacklist) then
						if (hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent:FindFirstChildOfClass("Humanoid").Health > 0) or (hit.Parent.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Parent:FindFirstChildOfClass("Humanoid").Health > 0) then
							didHitHumanoid = true
							local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") or hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
							table.insert(listOrIgnoreDescendantsInstance, humanoid.Parent)
							PrintDebug("Blacklist cast detected, added " .. tostring(humanoid.Parent) .. " to the blacklist.")
						else
							didHitHumanoid = false
							table.insert(listOrIgnoreDescendantsInstance, hit)
							PrintDebug("Blacklist cast detected, added " .. tostring(hit) .. " to the blacklist.")	
						end
					else
						-- This is where things get finnicky.
						-- We can't reparent the object. If we do this, we risk altering behavior of the developer's game which has undesirable effects.
						-- We need to swap cast functions on the fly here. This is gonna get NASTY. Oh well. It should only happen once under this new behavior.
						castFunction = CastWithBlacklist
						listOrIgnoreDescendantsInstance = listOrIgnoreDescendantsInstance:GetDescendants()
						if (hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent:FindFirstChildOfClass("Humanoid").Health > 0) or (hit.Parent.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Parent:FindFirstChildOfClass("Humanoid").Health > 0) then
							didHitHumanoid = true
							local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") or hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
							table.insert(listOrIgnoreDescendantsInstance, humanoid.Parent)
							PrintDebug("Stock cast detected, transformed cast into blacklist cast and added " .. tostring(humanoid.Parent) .. " to the blacklist.")
						else
							didHitHumanoid = false
							table.insert(listOrIgnoreDescendantsInstance, hit)
							PrintDebug("Stock cast detected, transformed cast into blacklist cast and added " .. tostring(hit) .. " to the blacklist.")						
						end					
					end					
				end
				
				-- So now just cast again!
				-- Cast with 0 deltaTime and from the prespecified point (this saves a smidge of performance since we don't need to try to recalculate a position value that will come out to be the same thing.)
				PrintDebug("Recasting for penetration...")
				Fire(0, at)
				
				-- Then set lastPoint.
				lastPoint = point
				-- We used to do ^ above, but this caused undesired effects and zero-length casts. Oops.
				
				if penetrationData ~= nil then
					if penetrationData.penetrationType ~= "WallPenetration" then
						if didHitHumanoid then
							penetrationCount = hit and (penetrationCount - 1) or 0
							PrintDebug("penetrationCount is reduced to... "..penetrationCount.." for hitting humanoid.")
						else
							PrintDebug("penetrationCount is not reduced for not hitting humanoid (or the humanoid died).")
						end
					else
						PrintDebug("DISTANCE: "..dist.." studs")
						PrintDebug("CURRENT PENETRATION DEPTH: "..penetrationPower.." studs")
					end
				end
				
				-- And exit the function here too.
				return
			end
		end
		
		-- Then set lastPoint here as well.
		lastPoint = point	
		distanceTravelled = distanceTravelled + rayDisplacement
		
		if distanceTravelled > distance then
			RemoveList[self] = true
			rayHitEvent:Fire(origin, rayDir.Unit, nil, lastPoint, nil, nil, Vector3.new(), cosmeticBulletObject, hitData)
		end
	end
	
	function self.Update(delta)
		Fire(delta)
	end

	--[[Thread:Spawn(function()
		Projectiles[self] = true
	end)]]
	-- Too fast?
	if RunService:IsClient() then
		spawn(function()
			Projectiles[self] = true
		end)
	else
		Thread:Spawn(function()
			Projectiles[self] = true
		end)
	end
end

local function BaseFireMethod(self, origin, directionWithMagnitude, velocity, cosmeticBulletObject, ignoreDescendantsInstance, ignoreWater, bulletAcceleration, bulletData, whizData, hitData, list, isWhitelist, penetrationData)
	MandateType(origin, "Vector3", "origin")
	MandateType(directionWithMagnitude, "Vector3", "directionWithMagnitude")
	assert(typeof(velocity) == "Vector3" or typeof(velocity) == "number", ERR_INVALID_TYPE:format("velocity", "Variant<Vector3, number>", typeof(velocity))) -- This one's an odd one out.
	MandateType(cosmeticBulletObject, "Instance", "cosmeticBulletObject", true)
	MandateType(ignoreDescendantsInstance, "Instance", "ignoreDescendantsInstance", true)
	MandateType(ignoreWater, "boolean", "ignoreWater", true)
	MandateType(bulletAcceleration, "Vector3", "bulletAcceleration", true)
	MandateType(list, "table", "list", true)
	-- isWhitelist is strictly internal so it doesn't need to get sanity checked, because last I checked, I'm not insane c:
	-- ... I hope
	-- However, as of Version 9.0.0, a penetrate function can be specified
	MandateType(penetrationData, "table", "penetrationData", true)

	-- Now get into the guts of this.
	local castFunction = Cast
	local ignoreOrList = ignoreDescendantsInstance
	if list ~= nil then
		ignoreOrList = list
		if isWhitelist then
			castFunction = CastWithWhitelist
		else
			castFunction = (penetrationData and penetrationData.penetrationType ~= "WallPenetration" and CastWithBlacklist or CastWithBlacklistAndNoHumPenetration) or CastWithBlacklistAndNoHumPenetration
		end
	end
	
	SimulateCast(origin, directionWithMagnitude, velocity, castFunction, self.LengthChanged, self.RayHit, self.RayExited, cosmeticBulletObject, ignoreOrList, ignoreWater, bulletAcceleration, bulletData, whizData, hitData, penetrationData)
end
