Warning: array_replace_recursive(): Argument #2 is not an array in /home/vstasks7/public_html/myvolleygame.com/wp-content/plugins/patron-button-and-widgets-by-codebard/index.php on line 1656

Warning: array_map(): Argument #2 should be an array in /home/vstasks7/public_html/myvolleygame.com/wp-content/plugins/patron-button-and-widgets-by-codebard/index.php on line 1659

Warning: array_replace_recursive(): Argument #2 is not an array in /home/vstasks7/public_html/myvolleygame.com/wp-content/plugins/patron-button-and-widgets-by-codebard/index.php on line 1656

Warning: array_map(): Argument #2 should be an array in /home/vstasks7/public_html/myvolleygame.com/wp-content/plugins/patron-button-and-widgets-by-codebard/index.php on line 1659

Warning: array_replace_recursive(): Argument #2 is not an array in /home/vstasks7/public_html/myvolleygame.com/wp-content/plugins/patron-button-and-widgets-by-codebard/index.php on line 1656

Warning: array_map(): Argument #2 should be an array in /home/vstasks7/public_html/myvolleygame.com/wp-content/plugins/patron-button-and-widgets-by-codebard/index.php on line 1659
And then A.I. was born – My Volley Game

And then A.I. was born

Volleyball is a game about interactions between players. But what if you don’t have another human to play with? Well, you need an A.I.

I decided that next gameplay mechanic I implement will be serve receiving. But to receive a ball, someone needs to serve it first. Good news is I already have serving mechanic that looks pretty solid for now. Bad news is that it requires a player control. It would be really awkward to serve and then receive the same serve. Therefore I needed a computer player to serve it for me.

AI rules are pretty simple (for now):

  1. Throw the ball in the air
  2. Wait until it reaches maximum height
  3. Randomize a place where ball should target (with possibility to overshoot)
  4. Randomize ball curve

Unreal Engine has a really cool feature to implement all kinds of AI behaviors – Behavior Trees. Here’s a screenshot of the tree driving our AI player:

In very simple words – every frame, actions are executed from the top to bottom, from left to right order. Blue rectangles represent “Decorators” which is just a fancy word for conditions. Purple rectangles represents actions. So the flow goes like this:

Every frame go through every single action in top-down left-right order and if condition is met, execute it.

Let me know in comments if you would like to read more in-depth explanations.

And here’s the result:

Pretty cool, huh?

Actually, the hardest part was to be able to switch between manual and AI control. It required refactor of almost all the serving logic (I don’t call it code, because it’s all in blueprints). But now I can easily take control of the player or let the AI drive it. It will come in handy later.

Now that the fundamentals are in, I will start work on actual receiving! Stay tuned!