Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 16874

Should units actually move during the AI logic, or separately?

$
0
0

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 …


Viewing all articles
Browse latest Browse all 16874

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>