Using simple neural networks in Unity

 


Using simple neural networks in Unity

Unity

Decided to try basic neural network to train character to survive longest when it is being shot at by regular AI.

Map: 10x10 grid with random obstacles to hide behind.

Enemies: simple point-and-go cells which will shoot if player is seen. Doesn't have any proper pathfind or anything. Their input is randomized - maybe this is why the results were not that great.

Scoring: how long did the character survive, how much damage it caused to enemies.

Scoring penalties: if character is hugging walls, gets hit, stands still.

Neural network inputs:
  • Tried to pass distances from walls in all sides. Not optimal.
  • Tried to pass distance and direction to nearest enemy. Bad.
  • Tried to add 360 degrees raycast results (wall/enemy/empty). Even worse.
  • Finally decided to add a grid of blocks around, which is color in specific color (wall/enemy/empty/projectile). This worked best.
Outputs:
  • Facing direction.
  • Move speed in that direction.
  • Shooting button.
Best of what it could do - evade projectiles like Neo in the Matrix and go hide in a corner until the time has run out. It managed to kill enemy like 2-3 times in 10 000 simulations, which is sad.

Comments