Ok, so to fix this problem I've added a boolean switch:
private var chRotation:Number = 0;
private var switchf:Boolean = false;
private var switchb:Boolean = false;
public override function update(delta:uint):void
{
if(target){
var smooth:Number = 0.95;
var tp:Vector3D = target.ghostObject.position;
var cp:Vector3D = entity.ghostObject.position;
var targetAngle:Number = -((180 / Math.PI) * Math.atan2(cp.z - tp.z, cp.x - tp.x));
if(oldTgRotation - targetAngle != 0){
if((oldTgRotation - targetAngle) > 300){
switchf = true;
}else if((oldTgRotation - targetAngle) < -300){
switchb = true;
}
}
if(switchf){
if(chRotation >= 177){
switchf = false;
chRotation = -180;
}else{
targetAngle = 190;
}
}
if(switchb){
if(chRotation <= -177){
switchb = false;
chRotation = 180;
}else{
targetAngle = -190;
}
}
chRotation += (targetAngle + (chRotation - targetAngle) * (smooth - (delta / 800))) - chRotation;
entity.ghostObject.rotation = new Vector3D(0, chRotation, 0);
oldTgRotation = targetAngle;
}
}