Magivoid Devlog #2 - Teams, AI, combat, and a thingamajig
Tags: gamedev, devlog
Published: 2023-05-02 14:16:34

---
title: Magivoid Devlog #2 - Teams, AI, combat, and a thingamajig
published: true
date: 2023-02-01 00:00:00 UTC
tags: gamedev, devlog
canonical_url: https://tinygame.dev/posts/Magivoid-Devlog-2/
---

## Teams

With a landscape and a character shooting fireballs in place, it’s time to add things that a game might have. Continuing our multiplayer MOBA-like concept, a solid addition at this point is the notion of teams. Luckily this was easy to do with the gameplay tag system in Unreal Engine. These tags are essentially just labels but implemented in a fairly performant way with indexed strings. I think they’re also cheap to replicate across the network, but I haven’t actually looked close at this.

I set up two bases, one red and one blue, with a lane between them and a thingamajig in the center. The idea for the goal of the game is to destroy the other team’s base. There will be minions spawning at specific intervals from each base, walking down the lane, and fighting any enemies they encounter. Once the minions reach the enemy base, they engage in destroying it. Simple and recognizable formula. I’m not sure what the thingamajig in the center will end up being, but I like the idea of having some object where the minions will presumably first encounter each other (unless the players intervene earlier).

![Our so called map](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uh8wo6fl6zqjqg65lquc.png)

## AI

The gameplay tags make it really easy to propagate properties through various code systems. I’ve already used the team tags in a few different places. First, there’s two spawn points, one at each base. The player character gets a specific team tag applied based on what spawn point they spawn at. Second, the base itself has a team tag applied to it. This will stop players damaging their own base, accidentally or otherwise. Third, the minions that spawn have a team tag applied. This will be used by the AI to identify who is and who isn’t an enemy. Fourth, and lastly for now, I use team tags on my waypoint actors.

![Waypoints in the editor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ao6jsekzzx3cjtpex7l.png)

The waypoints are just blueprints in UE that store an index and belong to a team. The index is used by the AI to know which waypoint to move towards. The minions, for now, have very simple behaviors: move down the list of waypoints and stop and shoot when an enemy is within range. If the minion gets to the enemy base, stop moving and start shooting until either the base or minion is destroyed.

You’ll notice in the screenshot above the waypoints for the blue team are just slightly above the waypoints for the red team. The behavior tree for the minion AI uses EQS queries to get random points around each waypoint for the minion to move towards so it’s always a slightly different path, though probably not noticeable. This should be enough for multiple minions to not pick the same location and bump into each other. In fact, minions from opposing teams wouldn’t bump into each other anyway as they would stop and shoot before they got close enough to touch.

Speaking of minions bumping into each other, right now there’s only one minion spawning at a time for each team. In traditional MOBAs there tends to be a set of minions walking together. Something to consider for later, but this will have to come once we can balance the gameplay a bit anyway, otherwise we’re just guessing what works at this point.

## Combat

The minions have a continuous enemy detection scan going that’s basically a simple visibility and distance check for player and AI actors. When an actor tagged as the opposing team is within range, the minion stops walking and starts shooting at that actor. The attack loop fires off three shots with a 0.5s delay between each, then a 1.5s delay, and repeat. The timing will likely need tweaking at some point once we start looking at damage values.

You might also have noticed in the screenshot above how the red and blue waypoints diverge around our thingamajig centerpiece. The red AI takes one path and the blue AI takes the other. When the minions from the two teams are circling around this area, they are actually within each other’s attack range. The cone however blocks their line of sight, which causes them to continue walking towards their next waypoint as if nothing happened. 

<video autoplay loop controls>
  <source src="https://tinygame.dev/assets/minion_avoid.9956a062.mp4" type="video/mp4" />
  Your browser does not support the video tag.
</video>

Technically that’s correct, they don’t see each other. This is purely an accident due to the minimal effort I put into creating the cone that serves as the centerpiece. If we replace it with a smaller object (or remove it), the minions would see each other and engage in combat.

<video autoplay loop controls>
  <source src="https://tinygame.dev/assets/minion_combat.090ee48b.mp4" type="video/mp4" />
  Your browser does not support the video tag.
</video>

I quite like the outcome of the minions not seeing each other. It means by default they bypass the encounter in the center and reach all the way to the enemy base. Unless, of course, one or both of the players interject. One option is to sprint (which we support through ALS) to reach the enemy minion and engage them in combat, causing them to stop and allow your own minion to advance farther. I hope to find additional ways to indirectly influence the AI behavior, but again this would be something for later.

A second unintended “feature” noticeable in the video above is the collision between minion projectiles. They don’t pass through each other so you get cases where they explode in mid-air.  The minion aim is randomized a touch at the moment (see [this blog post](https://tinygame.dev/posts/Simple-bullet-spread-for-AI/) for implementation details), so they don’t always collide. However, the projectile bounding sphere is fairly large and collisions do happen somewhat regularly. I love this result. As the great Mr Ross would say, we don’t make mistakes, just happy little accidents.


## Links

* [Gameplay tags](https://docs.unrealengine.com/5.1/en-US/gameplay-tags-in-unreal-engine/)
* [Environment Query System](https://docs.unrealengine.com/5.1/en-US/environment-query-system-in-unreal-engine/)
* [Paragon: Minions](https://www.unrealengine.com/marketplace/en-US/product/paragon-minions)
* [Professional Game Development in C++ and Unreal Engine (great course on UE)](https://courses.tomlooman.com/p/unrealengine-cpp?coupon_code=COMMUNITY15)