I'm using the dot product between the AI char's current right direction and a vector from the AI char to the target to determine if it should turn left or right.
Vec3 oPosRel = this.Pos - Target.Pos;
if (oDirection_Right.Dot(oPosRel) < 0.0f)
{
RotateRight(a_fDeltaTime);
}
else
{
RotateLeft(a_fDeltaTime);
}
This works 99% of the time.
Though if suddenly the ai needs to move in the opposite direction it gets stuck rotating in both directions left-right-left-right etc until finally, randomly it stops and rotates properly.
It seems to be relative to the size of "a_fDeltaTime" also. If I have a smooth 60 fps it never happens but if I zoom out dropping to 17 fps it happens every 1/20 direction changes or so.
Am I doing something wrong or should this work?
EDIT: Nvm. Solved ><