Trouble with bending around curves using traces

I was trying to make code that would make it so my earthshaker weapon would go around blocks and not just stop at the edge, and I was able to get it to work nearly perfectly when the attack is to the right. However, for some reason I can’t figure out, when I attack to the left it doesn’t work at all. It just stops at the edges of the blocks. Pics:

To the right:

To the left:

I would appreciate it immensely if someone helps me with this. The code’s kind of long, but it’s readable for the most part.

Note: dir starts as a line perpendicular to the player in the direction he’s looking.

[lua]
cur = cur+1

if(cur < 40) then

local tr_forward = util.QuickTrace( prevpos, dir*50, player.GetAll() )

if tr_forward.Hit then
	tr_up = util.QuickTrace( tr_forward.HitPos + tr_forward.HitNormal*25, dir:Angle():Up()*50, player.GetAll() )
	
	if !tr_up.Hit then
		dir = dir:Angle():Up()
		prevpos = tr_forward.HitPos + dir:Angle():Up()*25
		
		//do particle shit
		ParticleEffect("rock_impact_stalactite", tr_forward.HitPos, dir)
		ParticleEffect("rock_splinter_stalactite", tr_forward.HitPos, dir)
		WorldSound( "ambient/explosions/explode_4.wav", tr_forward.HitPos, 80 + cur*2, 60 + cur*2 )
	else
		cur = 0
		CanFire = true
		
		timer.Stop("shake")
	end
else
	local tr_down = util.QuickTrace( prevpos+dir*50, dir:Angle():Up()*-50, player.GetAll() )
	
	if !tr_down.Hit then
		local tr_back = util.QuickTrace( prevpos+dir*50+dir:Angle():Up()*-50, dir*-50, player.GetAll() )
		
		if tr_back.Hit then
			dir = dir:Angle():Up()*-1
			prevpos = tr_back.HitPos + dir:Angle():Up()*25
			
			//do particle shit
			ParticleEffect("rock_impact_stalactite", tr_back.HitPos, dir)
			ParticleEffect("rock_splinter_stalactite", tr_back.HitPos, dir)
			WorldSound( "ambient/explosions/explode_4.wav", tr_back.HitPos, 80 + cur*2, 60 + cur*2 )
		else
			cur = 0
			CanFire = true
			
			timer.Stop("shake")
		end
	else
		prevpos = tr_down.HitPos + dir:Angle():Up()*25
		
		//do particle shit
		ParticleEffect("rock_impact_stalactite", tr_down.HitPos, dir)
		ParticleEffect("rock_splinter_stalactite", tr_down.HitPos, dir)
		WorldSound( "ambient/explosions/explode_4.wav", tr_down.HitPos, 80 + cur*2, 60 + cur*2 )
		
	end
end

else
cur = 0
CanFire = true

timer.Stop("shake")

end

[/lua]

Have you checked to see what it may be hitting? It could be hitting some of that debris from your picture. Your trace filter is only set up for players.

Nonsense, traces don’t collide with particles. Hold on, something seems fishy with the way you calculate tr_back. I’m going to see if something behaves differently if you aim to the left or to the right.

Does it always work when you’re facing right?

I didn’t know they were particles. It looks like debris props to me.

[editline]02:46PM[/editline]

The only difference I see between those sides is that the right side has a debris effect or something, and since the trace seems to be stopping in the middle of it, I’d think it would be a good place to check.

I wouldn’t trust repeatedly converting dir into an angle, back into a vector and so on. Are you sure you can predict what dir:Angle():Up():Angle():Up() will give you?

I think you should store dir and dir:Angle():Up() in two separate variables, let’s call them “forward” and “up”. If you traces goes down, and then back, and collides with the world, you will rotate the whole system by changing “forward” into “up*-1” and “up” into “forward”. It’s much more reliable that way, and you will do less heavy angle calculations anyway.

Also HitPos returns the end of the trace if the trace didn’t hit. That will save you a lot of calculations as well.

[lua]cur = cur+1

if(cur < 40) then

local tr_forward = util.QuickTrace( prevpos, forward*50, player.GetAll() )

if tr_forward.Hit then
	tr_up = util.QuickTrace( tr_forward.HitPos + tr_forward.HitNormal*25, up*50, player.GetAll() )
	
	if !tr_up.Hit then
		forward, up = up, forward*-1
		prevpos = tr_forward.HitPos + up*25
		
		//do particle shit
		ParticleEffect("rock_impact_stalactite", tr_forward.HitPos, dir)
		ParticleEffect("rock_splinter_stalactite", tr_forward.HitPos, dir)
		WorldSound( "ambient/explosions/explode_4.wav", tr_forward.HitPos, 80 + cur*2, 60 + cur*2 )
	else
		cur = 0
		CanFire = true
		
		timer.Stop("shake")
	end
else
	local tr_down = util.QuickTrace( tr_forward.HitPos, up*-50, player.GetAll() )
	
	if !tr_down.Hit then
		local tr_back = util.QuickTrace( tr_down.HitPos, forward*-50, player.GetAll() )
		
		if tr_back.Hit then
			forward, up = up*-1, forward
			prevpos = tr_back.HitPos + up*25
			
			//do particle shit
			ParticleEffect("rock_impact_stalactite", tr_back.HitPos, dir)
			ParticleEffect("rock_splinter_stalactite", tr_back.HitPos, dir)
			WorldSound( "ambient/explosions/explode_4.wav", tr_back.HitPos, 80 + cur*2, 60 + cur*2 )
		else
			cur = 0
			CanFire = true
			
			timer.Stop("shake")
		end
	else
		prevpos = tr_down.HitPos + up*25
		
		//do particle shit
		ParticleEffect("rock_impact_stalactite", tr_down.HitPos, dir)
		ParticleEffect("rock_splinter_stalactite", tr_down.HitPos, dir)
		WorldSound( "ambient/explosions/explode_4.wav", tr_down.HitPos, 80 + cur*2, 60 + cur*2 )
		
	end
end

else
cur = 0
CanFire = true

timer.Stop("shake")

end
[/lua]

I didn’t test it, so save your code somewhere, I’m a bit tired and I might have screwed something up in the process.

[editline]08:51PM[/editline]

He posted the whole code. It’s all the same effects no matter which side he is on, and ParticleEffect generates nothing else than harmless clientside sprites.

Ah yes. Didn’t notice that. My mistake.

Thanks I’ll probably get to testing that tomorrow. Last day of school, kinda just goofing around all day.