Entity spins out

Hey guys, using AddAngleVelocity on a physobj. It is a vehicle that has its pitch and yaw face the same MoveAngles as your mouse. However, whenever the obj is facing 180 or 0 degrees, or close to them, it begins spinning out. I believe this to be a math problem in my code, if anyone could help me with this it’d be great.
inside Move hook:
[lua]
local mouseangp = mv:GetMoveAngles().p
local mouseangy = mv:GetMoveAngles().y
local angvel = Vector(0,0,0)
–local mouseang = mv:GetMoveAngles()
angvel = angvel + Vector(0, (mouseangp - entang.p) / 2, 0) – for pitch, calculates difference between current entity pitch and mouse yaw
angvel = angvel + Vector(0, 0, (mouseangy - entang.y)) – for yaw, calculates difference between current entity yaw and mouse yaw
self.Entity.AngVel = angvel[/lua]
in the FinishMove hook:
[lua] self.Entity:GetPhysicsObject():SetVelocity( mv:GetVelocity() )
self.Entity:GetPhysicsObject():AddAngleVelocity(self.Entity.AngVel) – apply force
print(self.Entity:GetPhysicsObject():GetAngleVelocity())[/lua]

bump, added the following, the spinning out seems to happen by the maths thinking it has to do a full spin around to get to where it wants to go, this is supposed to detect if the angle is bigger than 180 and take the shorter path accordingly
[lua]
if math.abs(mouseangp - entang.p) > 180 then
angvel = angvel + Vector(0, -(360 - (mouseangp - entang.p)) / 2, 0)
else
angvel = angvel + Vector(0, (mouseangp - entang.p) / 2, 0)
end
if math.abs(mouseangy - entang.y) > 180 then
angvel = angvel + Vector(0, 0, -(360 - (mouseangy - entang.y)))
else
angvel = angvel + Vector(0, 0, (mouseangy - entang.y))
end[/lua]
nothing changes, anyone know why?

EDIT: Actually maybe the angles aren’t in degrees like I thought. If they’re not in degrees what are they measured in, radians?

Why are you using Vectors instead of QAngles?

AddAngleVelocity() takes a vector as an argument, not an angle

You are treating the values as if they were angles, though. The Vector is actually a replacement struct for AngularImpulse, which is not capped at 360, but rather relative to magnitude.

Yeah I know I am, I’m just not very good at math so not sure what values I should be aiming for, other than that they should be proportionate to the ones I am currently using (difference between angle 1 and angle 2).

So, would AngularImpulse increase velocity at a rate of one degree / s^2 ? :confused: i think i need to do calculus on a circle or something