Virion devlog #13

2018/05/09

3 minute read

Summary

over the last 2 days the AI got a lot of attention. Moving to random tiles with in the range was annoying anyway so I implemented a target selection algorithm. The basics are the same for the algorithm I had used in the prototype. Pick the closest building based on euclidean distance and go towards that. This type of target selection may sometimes lead to what would seem as non optimal. Such as the case


. . . . .
1 x . @ .
. x . . .
. x . . .
. x . . .
. . . . .
. . . 2 .

@ = player
1 = target
2 = target
x = blocker

Here the closest target is 1 based on euclidean distance, when in fact the path to that target is way longer than the path to target 2.

But “optimal” is not what I’m searching for. It’s ok to make the game unpredictable at times, so it doesn’t get boring. After the target selection, I added the ability to show a target indication for enemies. This is actually a ‘threat’ indication as the attack will happen next turn. The enemies stay committed to the direction they are attacking if they lock on to a target and will attack in that direction if they are pushed/pulled or dislodged some other way. I also added the force move and it’s damage effects on the units. I realized that if a weapon can do more than 1 tile force move the code has to be in the movement class, as the damage effects need to be applied after the animation to that tile is complete. This lead to the need for seperating the movement animation code from the movement class into a seperate component. I also needed to add a “Fly” method that doesn’t check if the path to a target node contains blockers, as I want the unit to crash into the blockers. While at it I also changed the way the movement animations were done. Previously I was LERP’ing the movement between the tiles, which lead to a movement that gradually sped up when it was getting near to it’s target. Now I just use a simple method to calculate the amount to move and animate the movement in a linear fashion, which made the animations look better. The idea is quite simple, I don’t know why I didn’t do it in the first place:


distance = Speed * Time.deltaTime //distance to travel this frame
dir = target.position - my.position
if (dir.magnitude > distance) {
  translate(dir.normalized * distance)
} else {
  my.position = target.position
}

I also added an in game console, which I use for messages as the unity Debug.Log sucks.