# 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
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
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 ph=self.Gun:GetPhysicsObject()
``````

[/lua]

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