About Me

My photo

My goal is to make a difference in the world, and I think the way to do that is through games. My education is in programming and 3D animating, and I have worked in e-Learning and game development. 

Tuesday, August 22, 2017

Game AI: Non-Human Behavior Part 4

This is part 4 of a series on Game AI for Non-Human Behavior. Here's what you might have missed!
  • Part 1: Defining "Game AI" and "Non-Human Behavior"
  • Part 2: Making Decisions, Predators and Prey
  • Part 3: Weird Inspirations from Nature
 Today let's talk about how creatures in the wild go about hunting.

Living things need food to survive. There are different ways to get food - some plants make their own food, some animals eat plants, and some creatures hunt. Hunting generally refers to actively pursuing your food, but for the purpose of this post I'm going to expand it to include luring your food to come to you.

Source: https://www.youtube.com/watch?v=z5fOsgrAJiU
Here are a few of the tactics that predators use to catch their food:
  • Speed
  • Strength
  • Traps / Lures
  • Stealth / Camouflage
  • Teamwork
  • Built-in Tools (ie. claws and teeth)
The Venus Fly Trap is a fabulous example of  a lure / trap. Predatory plants have adapted this way of life because they live in environments where it is challenging to absorb nutrients from the ground using roots. So, they capture little packets of nutrients from the air in the form of insects. Predatory plants have different methods of luring prey including bright colors and sticky nectar. Once a fly is lured into the danger zone, the Venus Fly Trap has special hairs inside it's "mouth" that detect when something bumps against it. On the second bump, the trap will close. That's some interesting and clever behavior there - if it immediately started closing, the fly could still be airborne and would have an easier time escaping, so by waiting for the second bump the fly is lulled into a false sense of security thinking it can safely land. After the trap has closed, it waits for 5 more stimuli of the hairs before it begins digestion, to ensure the thing it trapped is actually an edible insect wriggling around.

Source: keywordsuggest.org/gallery/242369.html
Another clever take on luring prey is the Angler Fish, which has a glowy lure on top of it's head that attracts unsuspecting fish into its terrifying mouth. Using traps and lures can save a lot of energy, because you don't need to move around as much if your food comes to you.

Source: www.flickr.com/photos/uswildlifeimagescom/5733874585
Birds have some of the scariest built-in tools in the form of deadly talons. Talons can be used for a variety of killing purposes including dismemberment and squeezing to death, and can be used in combination with the beak to tear critters into bite-sized pieces (sometimes while the critter is still alive).

Source: http://tigers4kids.weebly.com/hunting--diet.html
Big Cats can cover the spectrum of strength, speed, stealth, and teamwork, but they are certainly not the only ones. Tigers are known for their tremendous strength which allows them to take down prey in their solitary lifestyle.

Source: http://southernafricatravel.com
Lionesses work together to bring down prey that would be much too large and fast to bring down solo. While working together, the lionesses also employ stealth to sneak up close to their prey before begging the chase.

Source: https://s-media-cache-ak0.pinimg.com/originals
Cheetah, being the fastest land animal, is a go-to example of using speed for hunting. Cheetahs can reach top speeds of 60 miles per hour, though only for short sprints. Perhaps more impressive than their top speed is how quickly they can start and stop a sprint.

Source: wideopenspaces.com/10-animals-school-humans-camouflage/
Leopards are a master of camouflage, their patterns of spots help them melt into the shadows of trees and brush.

Many of these methods of hunting can also be used by prey to avoid being hunted. Prey rely on their speed, strength, teamwork, and stealth to stay alive in a dangerous world. And all of these methods can be applied to your characters when design your AI's behavior in games.

Sunday, August 20, 2017

Game AI: Non-Human Behavior Part 3

This is part 3 of a series, if you are just joining in be sure to start at part 1!

Nature is weird, and full of constant surprises.There are a lot of things in nature that we still don't understand.Take for example these thousands of circles in the Kalahari desert:

Source: Africa, Netflix
We don't know what causes them...Scientists have suggested numerous options - but ruled all of them out - including poisonous plants, insects, and magnetism. There is so much about our planet that is outside of our understanding, and so much to draw inspiration from.

Source: Bill Nye the Science Guy 
People think science is pretty cool, that's why we have a large chunk of the entertainment industry using science to draw in their audience. As game developers, we can use that fascination to our advantage, to get our players excited.

Source: Niche, Game
I've been playing a game recently called Niche where the player controls a herd of animals and tries to help them survive. The game does some really interesting things with reproduction and genetics, allowing the player to alter the chances of certain traits, and choosing which animals will mate with each other. This game does a really great job of taking elements of nature and science that people find fascinating, and then turning those elements into engaging gameplay mechanics.

Source: Factorio, Game
Another game that I think does a great job with this is Factorio. In Factorio, the player plays as a character stranded on an alien planet, and the player needs to collect resources to build a rocket to get off the planet. A lot of the resources can't be used as raw materials, so the player builds a lot of different kinds of processing plants, essentially creating an entire factory from scratch. But the alien species living on the planet does not want to see their beautiful planet destroyed by pollution and over-harvesting. The more the player builds and expands, the more of the natural planet gets destroyed, and the angrier the aliens become. The aliens will attack the player and the base, because they are defending their planet. I really like the way this game makes you think about how your actions are impacting nature, and finding more sustainable and less invasive ways to do things is more challenging but helps keep you at peace with the creatures inhabiting the planet.

I've design characters and AI for a handful of games, and I've learned a few lessons from the process. Instinctively, it might seem that character design, combat, and behavior are all distinct design challenges that can be handled independently, but I've found that when it comes to the player interacting with the characters, these three things are very tightly intertwined, and they deserve to be designed together. There are games that have characters that just make sense because their character design feels perfectly aligned with their AI behavior, and the transition from behavior to combat seems completely natural and expected for how that character is perceived. On the other hand, I'm sure we've all played games where a character feels out of place, their behavior does not make sense for what that creature is, and the transition to combat feels clunky and unexpected.

I personally have fallen into this trap, and I'd like to think that I learned from my mistakes, and hopefully you can too. The very first game I worked on where I designed the AI and combat was a co-op exergame where two players work together to defeat giant robot spiders in an underground subway system.

We spent a lot of time designing and researching the exercise portion, and not a lot of time thinking about our enemies. We knew we needed something that would be immediately recognized as evil, we needed the player to be able to attack from a distance, and we wanted the enemies to swarm the player. A couple of interesting things that came from our design was that the spiders would come out of webs in the corners, so players could predict where they would come from, and some spiders could attack from a distance by spitting sticky webs at the player to temporarily trap them.

This project was over 5 years ago. I was the lead designer on this project so I was responsible for designing engaging enemies, but it was my first time designing anything related to AI, so I treated the character design, AI behavior, and combat completely separately, because I didn't know any better. I took the easy route - enemies were mainly different in their health and how much damage they could do, with the exception of the web-spitting spiders, and the only distinction for the boss was that she was huge and much stronger than the little minions, but no interesting differences and no narrative reason why there was one enormous spider surrounded by a horde tiny spiders.

Why are they robot spiders? What made them? The spiders are pretty scary, but their creator is probably pretty terrifying. Why are they attacking the player? Blood lust? Or are they defending their nest? Perhaps seeing a mother spider with an egg sac could help shed some light on their behavior. If I could go back and do it again, I would begin by considering why are these characters here, and what is their incentive to attack the player. I would also draw inspiration from nature to come up with more interesting behavior instead of run in and attack.

Source: The Hunt, Netflix
Spiders are bizarre but highly specialized hunters, with unique features and behavior adapted to any environment they live in.

Source: The Hunt, Netflix
This is a Portia Spider hunting another spider by dropping down on it from above. The Portia Spider specializes in hunting other spiders, so rather than building her own web she goes out on the hunt.

Source: The Hunt, Netflix
 This is a Spitting Spider that shoots poison out of its mouth at its prey. And this Spitting Spider could end up being a meal for Portia.

Source: Africa, Netflix
And here is a spider that is cartwheeling down a hill to escape a predator. Spiders are an amazing example of how their actual behavior in nature is probably more profound and well-designed than anything we could come up with when brainstorming a spider-based character for a video game. This world has wonders and terrors beyond our wildest imagination.

Source: Image By Jon Richfield
 If you are concerned that spiders are just not large enough in real life to inflict the kind of terror you are looking for, then allow me to present to you the Huntsman spider which can get up to one foot in diameter, and can move nearly a meter per second. That sounds pretty terrifying to me.

In part 4 I'm going to talk about modes of hunting (and avoiding being hunted) that can be found in nature.

Wednesday, August 16, 2017

Game AI: Non-Human Behavior Part 2

This is part 2 in my series on non-human game AI, if you missed part 1 check it out first!

In nature, survival and reproduction are the two biggest driving factors of decision-making.Let's start with survival.

Starting with the big picture view, we know that all living things require energy to live, ie. food, and organisms have evolved different techniques based on where they get their energy from. One way to break this down is to figure out whether a creature is a predator or a prey at various points in the food web.

At the top we have organisms that are always predators, and generally nothing hunts them. But moving down the chain, there are creatures hunt, but are also hunted. This is where we can see some interesting behavior trees. Just from the high level goal of "survival" these creatures will need to make decisions about which is more important - avoiding a predator or finding food. If food is plentiful, that decision is easy, but if that creature has gone a long time with out food they may take bigger and bigger risks to find food, encroaching into areas they know to be dangers.

From a design perspective, what's interesting here is we can use this information in two very distinct ways. 1. Some games, especially hunting games and some survival games, attempt highly realistic simulated environments with a balance of creatures that exist for the player to hunt. These games can use information about predator/prey relations to generate believable content. 2. Beyond realistic simulations, in any game with enemies we can regard to player as a part of the predator/prey relation. The player wants to survive, so she must defend herself from enemies either with stealth or armor or by attacking and killing the enemies first, however most games have other objectives and the player must decide how much risk they are willing to take to accomplish those objectives.

In any scenario in games that have enemies, we can decide - do we want the player to feel like a predator here, or prey? Do we want the player to feel sneaky and clever and avoid getting caught/killed, or do we want the player to feel powerful and dominant and on the hunt? Both options create interesting dynamics, and a lot of games alternate between the two to create powerful exciting experiences.

As an example, in World of Warcraft if you encounter a high-level creature too early you will probably try to avoid it because you know it's stronger than you, but once you have leveled up you might return to fight it once you know you have a chance to defeat it.

Let's design an AI for a creature that is in the middle of a predator/prey situation. I like to think of AI decision-making systems as a sort of pro-con list:

This gives us an idea of the possible behaviors the AI might take, and what some of the factors are that determine that decision. Based on our pro-con list, we know that the primary decision we want to focus on is "stay and eat" vs. "run and hide" and we know that some of the factors include how hungry they are, how prevalent the food is, how dangerous the predator is, how close the predator is, and whether or not the predator has seen them. Now we can work on prioritizing these and converting them into a decision graph (or a behavior tree or state machine, depending on your approach).

This would obviously be different for different types of creatures, and it is also a very simplified solution - it only covers one very specific decision and two possible behaviors. Generally AI will have a lot of possible behaviors and different decision factors across the spectrum of possibilities. That is really what makes AI design such a challenging area to work in.

The complexity of the AI design depends heavily on how realistic the behaviors need to be. In theHunter:Call of the Wild the designers knew that players wanted a realistic hunting experience, and that often players would spend a lot of time watching an animal before taking a shot, so the designers had to be prepared to do extensive research on how those creatures behaved to ensure a believable experience for the player.

Most games are not held to quite such high standards of realism. Creatures in Legend of Zelda do not have parallels in real life, so they have the flexibility to be weird and wonky and still be believable.

In part 3 I'm going to get into some of the stranger behavior in nature, and how we can use it as inspiration in AI design.

Image Sources:

Thursday, August 10, 2017

Game AI: Non-Human Behavior Part 1

In this series I will be talking about game AI, specifically designing behaviors for non-human characters. At the end of August I will be speaking on this topic at PAX Dev, so this blog series is where I will be organizing my material and hopefully getting some feedback! So let's get started.

Game AI is one of those areas of game development that is both very technical and very design-heavy. However, it is important not to overlook the role that art and sound play in making the AI believable, understandable, and relatable. When we talk about AI in games, we are talking about anything in the game that makes decisions for itself, and specifically what is the process for making and acting on those decisions. We often use either a behavior tree, or a state machine, or some combination of the two, to determine what an AI is going to do at any given moment. The AI also needs to store and process information about its surroundings and its past actions to use in its decision-making.

I think it's safe to say that we are all humans, and so when we approach a design problem we approach it from the human perspective. When designing something that makes decisions, we instinctively design it to make decisions the way we make decisions. Obviously this works out well when designing AI for human characters, but not so well when designing for non-human characters.

There are plenty of people out there talking about game AI for human characters, and they know way more on that subject than I do, so for this talk I will not be covering anything to do with humans. When I say "non-human AI" you are probably thinking of animals, and specifically of mammals, probably most likely mammals on our size-scale like cats.

I'm going to talk about more than just cat AI, in fact I'm going to go beyond mammals or animals in general. There are a lot of options out there for non-human inspiration and design - fish, birds, insects, arachnids, plants...robots...zombies...aliens...I mean, like, real aliens...

(not an alien, this is a real Earth creature)


Let's talk about what constitutes AI in games. First I need to clarify, AI for games is not at the same caliber as AI in the world of computer science and machine learning. AI for games is essentially dumb AI, it is constrained to what is needed for gameplay purposes and to appear to be making informed decisions to fool the player. In fact, not only does AI in games cut corners, it also often has hindrances applied to it to make it feel more believable and natural to players. Players tend to feel cheated if the AI seems too smart, even if it is accurately acting on the information it is given.

Ok, so Game AI is not the same as real AI. Let's also talk about some definitions, just for the sake of clarity. An Agent is something that uses information to make a decision through a process of Action Selection. An Agent in a game could be a friendly NPC, an enemy, a semi-controllable simulated character, or in some cases a background character, or a companion (such as a pet). AI Agents generate responsive behavior based on a predetermined set of stimuli, to give the illusion of intelligent decision-making.

Now on to the point of this series: how do we as humans design AI for things that are not humans? There is also a larger problem here, once we manage to design something that does not make decisions the way we do, how do we make sure the player understands those characters and their decisions? Not surprisingly, a common way to make non-human characters relatable is to anthropomorphize them.

Let's avoid that approach for now, because if we are going to anthropomorphize our characters then there is no real reason they shouldn't make decisions like humans. In this series I am going to talk about some amazing things that really exist, things we can use as inspiration for our AI design. Things like flocking, hive-mind, predator/prey relations, natural selection, and aggressive plants. Stay tuned!

Food for thought: if a tree grew fast enough that we could watch it engulf something, how scary would that be?

Friday, June 16, 2017

Death's Daughter

The second team of interns at Astire Games just wrapped up their project Death's Daughter. It is an endless runner on Android and iOS where you play as the daughter of the Grim Reaper helping him reap souls.

Some cute and interesting things they did with their mechanics - the character you play is very young, and the souls weigh her down both figuratively and literally. She carries the souls in a bag on her back and drops them off at courier checkpoints, but as the bag fills with souls she moves slower and it becomes more difficult to clear obstacles. If her bag has too many souls it will tear open and she will drop them all and have to start over. One of the obstacles she faces is a black cat, which gives nine souls if she hits it - this can be good or bad for the player depending on how full your bag is!

The game went live today on Google Play and iTunes, but the interns will be continuing their internship for another week to release updates to the game based on reviews and feedback from players. We hope you will play and give feedback!

Friday, May 12, 2017

Game Prototyping in Unity, Part 3: Character Controller

This is a continuation of my blog post series about a tutorial I made called Game Prototyping in Unity available on Pluralsight. If you haven't read the previous entries, check out Part 1 on whiteboxing and Part 2 on art and sound integration.

There are many times when you don't need to make a character controller from scratch - a lot of simple first-person games use Unity's default first-person controller. You may also have a game where a character controller is not needed at all, such as a top-down strategy or puzzle game. Unity also has a third-person controller, which can work well in some circumstances. However, if you know the kind of behavior your want from your character controller, it is sometimes easier to make it yourself rather than trying to find one that suits your needs.

When designing a character controller, I like to first imagine how I want the player to see the world and the character. Do I want the player to be up close to the environment, seeing things first-hand?

Or do I want the player to see the character they are playing, see that character's animations and how that character interacts with the world?

For this game we will make a third-person character controller.

The next decision to make is deciding what the player's input will be to move the character. In some third-person games, the player clicks a point for the character to move there. In other games the player uses WASD or the controller joystick to move the character. There are also cases where the character moves automatically based on the context of the world - ie. moving toward an NPC to talk to them.

Since we want to offer controller support for this game, it makes the most sense to use WASD since that has a direct mapping to the controller joystick.

We also need to ask ourselves "Can the player control the camera?"

In some third-person games the camera automatically follows the character with no input from the user. In other games, the user controls the camera with the mouse or with the right joystick. We will use the latter option.

For this character controller I've decided to use Unity's NavMesh because it automatically handles keeping the player on the ground and smooth gradual movement. The NavMesh allows you to determine if objects in the scene are "walkable" - meaning the top of the object is a surface the player can walk on - or "not walkable" - meaning that object is an obstacle or in some way inaccessible. Once you'd baked the NavMesh you can see what areas the player can walk on as a blue surface.

The scripting part is fairly simple, we just need to attach a NavMeshAgent component to our character and then tell it which was to move.

Unity also comes with a "Smooth Follow" script which can be attached to the camera and set to target the character, that was the camera moves when the character moves. We can also use Unity's "Simple Mouse Rotator" script to give the player control of the camera direction.

The final step is going to be giving the player a ranged attack. A ranged attack can be anything that is fired from a distance such as a gun or a spell. I think a spell would work better in the kind of world I am creating, so I will make a projectile object with a particle effect like a spell, and put it in a folder called "Resources" (it's important this one is spelled correctly, because this is the only folder Unity can load from at runtime).

Then we need to instantiate that projectile when the player fires.

Then on the projectile itself we want to tell it to move forward on every frame (since we are instantiating it facing the direction we want it to move, it should only ever move forward).

And that's it! Now we have a third-person character controller that moves with WASD and uses the mouse to look around, and can cast a spell at enemies.

Check out the full video tutorial on Pluralsight! Section 4 will cover scripted interactions.

Tuesday, May 9, 2017

Game Prototyping in Unity, Part 2: Art and Sound Integration

This is Part 2 of my short blog series "Game Prototyping in Unity" about my recently released tutorial. If you have not already read Part 1 I recommend starting there!

In the second module of my tutorial I cover integrating art and sound in Unity and adding lighting and particles.

The first step is bringing in your model and texture files.

Then you will create a new material in Unity. Unity materials have a lot of properties you can work with, but the easiest ones to start with are the diffuse color (which is just the color of the material), normal color (which determines the detail or roughness of the surface), and specular or metallic color (giving it a shiny quality).

When you are done setting up your models with materials and textures, you can turn each art asset into a refab and replace your whitebox with art.

Make sure there are no areas where the player can walk out of the level. You don't need to follow your original layout, just use it as a general guide.

Once your layout is replaced with art it's time to add some lighting. For this type of level I want to use torches to give it a medieval feel. So I used a fire effect from Unity's default particle package and made some modifications so it would fit with this art style.

The flame particle system comes with a point light, but I also like to add a couple more point lights around each torch so you can see the details of the torch.

Once you have your bright areas, be sure to give some thought to lighting your dark areas. It's tempting to just keep dark areas unlit and leave them mostly black, but that generally doesn't look good in games because the player really can't see anything at all.

If you want to keep the feeling of darkness but still give the player enough visibility to play, use some dark blue lighting to fill the darkest areas.

When you are done, you'll have a well-lit level that conveys mood as well as giving visibility.

The final step in asset integration is adding sound effects. Rather than attaching ambient sounds to the main camera, try adding ambient audio sources as 3D sound around the scene, so as the player walks the sound changes. This helps bring the level to life.

If you enjoyed this blog post, please check out the video tutorial on Pluralsight which will take you step-by-step through this whole process! The next section will cover creating a character controller.

Thanks for reading!