SetAngles Not Working Properly When Looking Up/Down

Hi, I’m working on fixing up an old SWep addon, but i’ve come across a problem I can’t seem to fix. The SWep spawns an entity and fires it but when it sets the angles for the entity, if you are looking directly up or down, the entity’s angle is only set for 2 directions. Anyone know why this might be happening?

Here is an image to demonstrate what I mean:

Here is the code that is setting the angles for the entity:


if (SERVER) then
		local plasmabullet = ents.Create("plasma_bullet")
		if (IsValid(plasmabullet)) then
		local aimang = self.Owner:GetAimVector():Angle()
		local accmul = self.overheat / 20
			plasmabullet:SetOwner(self.Owner)
 			plasmabullet:Spawn()	
			plasmabullet:SetPos(self.Owner:GetShootPos())
			if !self.Owner:IsNPC() then
				plasmabullet:SetAngles(aimang + Angle(math.random(-accmul, accmul), math.random(-accmul, accmul), math.random(-accmul, accmul)))
				self.Owner:RemoveAmmo( 1, self.Primary.Ammo )
			else
				plasmabullet:SetAngles(aimang)
			end
		end
		local phy = plasmabullet:GetPhysicsObject()
			if phy:IsValid() then phy:SetVelocity(plasmabullet:GetForward()*9999999 + self.Owner:GetForward())
		end
	end

Bump, figured out it has something to do with the yaw value.

[editline]27th June 2017[/editline]

For whatever reason, the yaw value seems to be acting as some kind of multiplier. THis doesnt happen with the pitch or roll parts of the angle, and it does this whether I use a set value or the overheat value.

Just glancing at it, are you sure you want to be using:
[lua]local aimang = self.Owner:GetAimVector():Angle()[/lua]

This gets you a normal of a normal, and NOT where the player is aiming, you’re also adding angles after getting the Forward(), which can lead to some unexpected results. Here is how I would do it:
[lua]
local plasmaBullet = ents.Create( “plasma_bullet” )
if IsValid( plasmaBullet ) then
plasmaBullet:Spawn()
plasmaBullet:SetOwner( self.Owner )
plasmaBullet:SetPos( self.Owner:GetShootPos() )

if self.Owner:IsPlayer() then
	local accmul = self.Overheat / 20
	plasmaBullet:SetAngles( self.Owner:EyeAngles() + Angle( math.random(-accmul, accmul), math.random(-accmul, accmul), math.random(-accmul, accmul) ) )
	self.Owner:RemoveAmmo( 1, self.Primary.Ammo )
else
	plasmaBullet:SetAngles( self.Owner:EyeAngles() )
end

local bulPhys = plasmaBullet:GetPhysicsObject()
if IsValid( bulPhys ) then
	bulPhys:SetVelocity( plasmaBullet:GetForward() * 9999999 )
end

end
[/lua]

Also, unless this “plasma_bullet” entity has any special physics behaviors, instead of creating one and giving it an incredibly high velocity (entity based bullets can be incredibly expensive), why not just use the standard FireBullets() function that handles lag compensation and prediction for you.
You could also just replace the default tracer with whatever this weapon is using and add any effects through lua effects and handle any special bullet behavior in the FireBullets() bullet callback (For example, make the bullets vaporize the enemy)

Doesn’t :Forward() just return the vector of an angle? Trying to set an angle using that would cause an error wouldn’t it?

Oops. Was thinking about FireBullets() (which I still reccomend) where you feed it a vector instead of an angle for direction. I’ve updated the code in my initial post.

I tried your code, it comes out with the exact same effect as described in my original post. Also, I would usually use :FireBullets(), but i’m trying to replicate a weapon from another game.

Try this:

[lua]
plasmaBullet:SetAngles( self.Owner:EyeAngles() + Angle( math.random(-accmul, accmul), math.random(-accmul, accmul), 0 ) )
[/lua]

Still the same unfortunately

Sorry for the trial and error, if this doesn’t work, I’ll set up a entity bullet for testing and see if I can get it working if this doesn’t.

[lua]
local plasmaBullet = ents.Create( “plasma_bullet” )
if IsValid( plasmaBullet ) then
plasmaBullet:Spawn()
plasmaBullet:SetOwner( self.Owner )
plasmaBullet:SetPos( self.Owner:GetShootPos() )

local bulAng = self.Owner:EyeAngles()
if self.Owner:IsPlayer() then
	local accmul = self.Overheat / 20
	bulAng = self.Owner:EyeAngles() + Angle( math.random(-accmul, accmul), math.random(-accmul, accmul), 0 )
	self.Owner:RemoveAmmo( 1, self.Primary.Ammo )
end
plasmaBullet:SetAngles( bulAng )

local bulPhys = plasmaBullet:GetPhysicsObject()
if IsValid( bulPhys ) then
	bulPhys:SetVelocity( bulAng:Forward() * 9999999 )
end

end
[/lua]

Still the same. Thanks for the help, i’m fine with trial and error. I also just noticed this same problem on another addon I made.

To be honest I think this might be a bug with the game. I’ve tried a few things and it still happens. I’ve seen this happen on other addons too, but I don’t ever remember this being a problem before, as it used to work fine on older versions of GMod.