Make a turret entity with rotation speed.

I have a simple scripted turret entity, and i use the following to make it face it’s target, if it’s at all relavant:


function ENT:FollowEnemy(enemy)

local ang = ((self:GetPos() - enemy:GetPos())*-1):Angle()
local yaw = ang.yaw
local pitch = ang.pitch


self.base:SetAngles(Angle(0,yaw,0))
self.gun1:SetAngles(Angle(pitch,yaw,0))
self.gun2:SetAngles(Angle(pitch,yaw,0))

--self.base is the main body, and gun1/gun2 are the arms


end

using this, my turret simply snaps to face it’s enemy instantly.

I’m trying to figure out a way to give my turret a rotation speed.
any ideas?

Could anyone give an example of how to use this?
i’ve been toying with it for a week and it seems to do nothing i want it to.


function ENT:FollowEnemy(enemy)

local ang = LerpAngle(0.1,self:GetAngles(),((self:GetPos() - enemy:GetPos())*-1):Angle())
local yaw = ang.yaw
local pitch = ang.pitch


self.base:SetAngles(Angle(0,yaw,0))
self.gun1:SetAngles(Angle(pitch,yaw,0))
self.gun2:SetAngles(Angle(pitch,yaw,0))

end

Didn’t test, but this example should rotate towards the enemy at 10% of the angle diffrence per FollowEnemy call. You might want to store the initial angle or do some other method to make it linear, as this would slow down rotation as it gets more towards the desired angle.