Need Help with Angle Logic

Hello there. I’m not a newbe at lua, but I never have been good with angles and its logic.
I’m trying to turn 2 entities, constrained with an axis, to a certain target.
My version works pretty fine, unless you change the roll of that thing.
It will somehow point to the direction of the target, but not directly, sometimes 30° off.
By the way, target is the view of the player.
My version: (simplified)
[lua]
–entity 1, turns on y-axis (pitch)
function ENT:PhysicsUpdate(ph)
local vAngVel=ph:GetAngleVelocity()
local aAngSelf=self:GetAngles()
local fPitch=self.Player:GetAimVector():Angle().p
ph:AddAngleVelocity(Vector(0,math.AngleDifference(fPitch,aAngSelf.p),0)-vAngVel)
end

–entity 2, turns on z-axis (yaw)
function ENT:PhysicsUpdate(ph)
local vAngVel=ph:GetAngleVelocity()
local aAngSelf=self:GetAngles()
local fYaw=self.Player:GetAimVector():Angle().y
ph:AddAngleVelocity(Vector(0,0,math.AngleDifference(fYaw,aAngSelf.y))-vAngVel)
end
[/lua]

I would appreciate it if somebody could help me with that one.

Heh, it’s pretty easy, although it doesn’t really contain angles.

[lua]

local ph=self.Turret:GetPhysicsObject()
local zadd=(self.Turret:WorldToLocal(vTargetPosition)/fDistance*100).y
ph:AddAngleVelocity(Vector(0,0,zadd)-ph:GetAngleVelocity()+angvel)

local ph=self.Gun:GetPhysicsObject()
local yadd=(self.Gun:WorldToLocal(vTargetPosition)/fDistance*100).z
ph:AddAngleVelocity(Vector(0,0,yadd)-ph:GetAngleVelocity()+angvel)

[/lua]

Turns the target position to a local from view of the gun, and adds y/z to the angle velocity.