Bullets won't react

I started late last year tweaking GDCW because I liked the pack and most of the problems I found were easy fixes.
I took a few months off, but now I’m back at it.

The issue I’m having is that I can’t get the bullets to react to anything within ~50yds.
Past that, impact effects and shot decals start firing and acting normal. Another peculiarity is that I can get the bullets to interact within that distance, but they have to be shot through thin, solid objects first (tin sheet, corners, etc.).

I’m almost convinced it’s a physics problem and I’m almost tempted to re-write this whole thing using PhysicsSimulate…

Here’s a largely stock bullet entity. I turned it back this way because all my fiddling was getting me nowhere.
[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

local mats={ // Multipliers for materials
[MAT_SLOSH] ={3},
[MAT_FLESH] ={2},
[45] ={2}, // Metrocop heads are a source glitch, they have no enumeration
[MAT_DIRT] ={2},
[MAT_WOOD] ={1.5},
[MAT_SAND] ={1.3},
[MAT_GLASS] ={1.2},
[MAT_CLIP] ={1},
[MAT_TILE] ={1},
[MAT_GRATE] ={0.8},
[MAT_VENT] ={0.8},
[MAT_METAL] ={0.3},
} // This determines how much the bullet will penetrate in stuff

function ENT:Initialize()

self.Owner = self:GetOwner() // Who dun it!
self.Penetrate = 16 // How deep Generic Default goes
self.Flightvector = self.Entity:GetUp()((84052.5)/66) // Velocity in m/s, FIRST NUMMER is SPEED (FrameTime)
self.Timeleft = CurTime() + 5 // How long before auto-remove?
self.Impacted = false // Important for flight continuation, see line 173
self.Splatter = false // Carries blood and AIDS after the round passes through someone
self.EffectSize = 1.3 // How much stuff gets kicked up on impact
self.TissueDamage = math.Rand(35,55) // Player damage is multiplied by 2 for some reason
self.BallisticDrag = 90 // Fraction of velocity lost per tick, higher is less
self.Drift = 0.1 // How much the bullet will drift in flight (Inaccuracy)

self.Entity:SetModel( “models/led.mdl” )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_NONE)
self.Entity:SetSolid( SOLID_NONE )

Trail = ents.Create(“env_spritetrail”) // The streak of the tracer
Trail:SetKeyValue(“rendercolor”,“255 150 100”)

Glow = ents.Create(“env_sprite”) // The ball of the tracer
Glow:SetKeyValue(“rendercolor”,“255 150 100”)

Shine = ents.Create(“env_sprite”)
Shine:SetKeyValue(“renderfx”, “0”)
Shine:SetKeyValue(“rendermode”, “5”)
Shine:SetKeyValue(“renderamt”, “255”)
Shine:SetKeyValue(“rendercolor”, “255 130 100”)
Shine:SetKeyValue(“framerate12”, “20”)
Shine:SetKeyValue(“model”, “light_glow03.spr”)
Shine:SetKeyValue(“scale”, “0.25”)
Shine:SetKeyValue(“GlowProxySize”, “1”)


function ENT:Think()

--if self.Impacted  then self.Impacted = false end	// Reset this part so it can tell at the end

	if self.Timeleft < CurTime() then		// In case of an error, all rounds will self-remove after a few seconds

Table		={} 					//Table name is table name
Table[1]	=self.Owner 				//The person holding the gat
Table[2]	=self.Entity 				//The cap
local trace 	= {}
trace.start 	= self.Entity:GetPos()
trace.endpos 	= self.Entity:GetPos() + self.Flightvector	// Trace to where it will be next tick
trace.filter 	= Table
trace.mask 	= MASK_SOLID + MASK_SHOT
local tr = util.TraceLine( trace )

	if tr.Hit then
		if tr.HitSky then
		return true
		if tr.MatType==83 then				//83 is wata
			local effectdata = EffectData()
			effectdata:SetOrigin( tr.HitPos )
			effectdata:SetNormal( tr.HitNormal )		// In case you hit sideways water?
			effectdata:SetScale( 15*self.EffectSize )	// Big splash for big bullets
			util.Effect( "watersplash", effectdata )
		return true

		local effectdata = EffectData()
		effectdata:SetOrigin(tr.HitPos)				// Position of Impact
		effectdata:SetNormal(tr.HitNormal)			// Direction of Impact
		effectdata:SetStart(self.Flightvector:GetNormalized())	// Direction of Round
		effectdata:SetScale(self.EffectSize)			// Size of explosion
		effectdata:SetRadius(tr.MatType)			// Texture of Impact
		util.Effect("universal_impact", effectdata)
		util.ScreenShake(tr.HitPos, 10, 5, 0.1, 200 )
		util.Decal("ExplosiveGunshot", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)
			if self.Splatter then 				// If the bullet has hit blood, make it splat on walls
			util.Decal("blood", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)

		if tr.Entity:IsValid() then
		local dmginfo = DamageInfo()
		dmginfo:SetDamage( self.TissueDamage ) 
		hitgroup = tr.HitGroup

if hitgroup == HITGROUP_GENERIC then dmginfo:ScaleDamage( 1 ) elseif
hitgroup == HITGROUP_STOMACH then dmginfo:ScaleDamage( 1 ) elseif
hitgroup == HITGROUP_GEAR then dmginfo:ScaleDamage( 1 ) elseif
hitgroup == HITGROUP_CHEST then dmginfo:ScaleDamage( math.Rand(1,1.5) ) elseif
hitgroup == HITGROUP_LEFTARM || hitgroup == HITGROUP_RIGHTARM then dmginfo:ScaleDamage( math.Rand(0.3,0.5) ) elseif
hitgroup == HITGROUP_LEFTLEG || hitgroup == HITGROUP_RIGHTLEG then dmginfo:ScaleDamage( math.Rand(0.3,0.6) ) elseif
hitgroup == HITGROUP_HEAD then dmginfo:ScaleDamage( 5 ) else
dmginfo:ScaleDamage( 1 ) end
dmginfo:SetDamageType( DMG_BULLET ) //Bullet damage
dmginfo:SetAttacker( self.Owner ) //Shooter gets credit
dmginfo:SetInflictor( self.Entity ) //Bullet gets credit
dmginfo:SetDamageForce( self.Flightvector:GetNormalized()self.EffectSize3 ) //A little thump…
tr.Entity:TakeDamageInfo( dmginfo ) //Take damage!
if (tr.Entity:IsPlayer() || tr.Entity:IsNPC()) then
self.Splatter = true
util.Decal(“blood”, tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal) //Splat all over them

	local Dot = self.Entity:GetUp():DotProduct(tr.HitNormal)
	if (Dot*math.Rand(0.04,1)*mats[tr.MatType][1])>-0.04 then		// If it doesnt hit head on,
		self.Flightvector = (self.Flightvector:Length()*(1+Dot*1.2)) * (self.Entity:GetUp()+(tr.HitNormal*Dot*-0.8)+(VectorRand()*0.1))
		self.Entity:SetAngles(self.Flightvector:Angle() + Angle(90,0,0))
		self.Entity:NextThink( CurTime() )
		return true

			// This part is for realistic bullet penetration
			// Generic Default penetrated your mom......

self.Mat = math.ceil(tr.MatType)								// Multiplier for materials
local trace = {}
trace.start = tr.HitPos + self.Flightvector:GetNormalized()*(self.Penetrate*mats[self.Mat][1])	// Start in front of the bullet
trace.endpos = tr.HitPos									// Trace back to the impact
trace.filter = self.Entity 
trace.mask 	= MASK_SHOT
local pr = util.TraceLine( trace )

if pr.StartSolid || tr.Hit and !pr.Hit || self.Penetrate<=0 then	// If you start inside something, it's too thick
self.Entity:Remove()							// So remove the bullet

self.Penetrate = self.Penetrate-(tr.HitPos:Distance(pr.HitPos)/mats[self.Mat][1])	// Subtract to get the penetration depth
if self.Penetrate<=0 then								// If it runs out of inertia, remove it

self.Entity:SetPos(pr.HitPos + self.Flightvector:GetNormalized())	// Start at the point of exit + 1
self.Impacted = true							// This prevents it from moving twice later on

local effectdata = EffectData()
effectdata:SetOrigin(pr.HitPos)						// Position of Impact
effectdata:SetNormal(self.Flightvector:GetNormalized())			// Direction of Impact
effectdata:SetScale(self.EffectSize)					// Size of explosion
effectdata:SetRadius(pr.MatType)					// Texture of Impact
util.Effect( "universal_penetrate", effectdata )					// Make some debris
util.ScreenShake(pr.HitPos, 10, 5, 0.1, 200 )						// Compression in the material
util.Decal("ExplosiveGunshot", pr.HitPos + pr.HitNormal,pr.HitPos - pr.HitNormal)	// Bullet hole in the exit

end								// This one ends the penetration code
end								// This one ends the impact code

if !self.Impacted then
self.Entity:SetPos(self.Entity:GetPos() + self.Flightvector)
end								// This one sets a normal flight path if there is no impact

self.Flightvector = self.Flightvector - self.Flightvector/self.BallisticDrag + (VectorRand():GetNormalized()*self.Drift) + Vector(0,0,-0.111)
self.Entity:SetAngles(self.Flightvector:Angle() + Angle(90,0,0))
self.Entity:NextThink( CurTime() )
return true
end // Ends the think function and loops the bullet code

(User was banned for this post ("wrong section" - postal))

You can’t expect us to fix a whole page of code for you. And you’ve posted it in the wrong place :stuck_out_tongue:

Oh, lord no. I’ll fix it, I just can’t pinpoint whats wrong with it.
I enjoy doing codework. Just get stumped sometimes. When you’ve been staring at something for hours and hours, it’s easy to overlook something.
At the very least, I was looking for a “hey, dumbass, what the hell is this?” so I can get a new light and get back on track.

Also, sorry about the wrong section. Is part of an addon, so I though 'twas appropriate.
It fit better here per the descriptions better than anywhere else.

(Mods: Please move this to Develpoer Discussion. Saw the sticky after-the-fact.)

Something else I was thinking is that perhaps the velocity of the object to too high for my tick rate (33), resulting in it not actually spawning until a good distance out. Thoughts?