Currently my general logic for anything from turrets to fully mobile units is to do the movement as pay of the logic so can act of it. E.g. a simple form of the turret logic might be:
update_turret ()
{
if (!_target || ! can_hit_target ())
select_target();
if (!_target) // give up
{
turn_towards(_idle_dir); //actually move
}
else
{
auto wanted_dir = direction(_pos, _target->pos());
turn_towards(wanted_dir);
if (_dir == wanted_dir) // move
shoot();
}
}
Where `turn_towards` considers the current and desired direction, max turn rate, etc.
For fully mobile units there are a bunch of methods mostly calling a `move_speed(speed, direction)` to try and turn and accelerate to a …