Game Development | Monsters And Trying Out Different AI Capabilities

in Hive Gaming4 years ago

Monsters And Trying Out Different AI Capabilities.png

It has been an interesting week of trying to learn, impalement, fix bugs, and sometimes just not fully understand why things are not working. There is a long list of things that come with implementing creatures for the player to interact with. You can have a basic AI that can at least get the job done—most of the time. Finally, there is the madness of jumping down the AI rabbit hole of capabilities when wanting something more advanced.

Unreal Mannequin Skeleton

Unreal Engine 4 Mannequin Skeleton.png

Unreal Engine 4 has some neat things that can make it easy for a solo indie developer to get a lot done quickly as long as they line up with what they already have implemented. This is something I took advantage of when I could over the past week. One of those things is how bones and skeleton systems work.

I’ll admit when I first started trying out Unreal Engine 4 many months ago the Mannequin was something I always overlooked. It was a basic humanoid that at least enabled me to run around in maps until I had something better. Then I kind of tossed it aside and never gave it much thought.

That was until I had a bunch of other humanoids that I wanted to start using with the end goal of having the player fight them. What is interesting is the Mannequin Skeleton is considered to be a bit of a standard in the proper way of setting things up for similar shape creatures in Unreal Engine 4. Which means there are massive amounts of things out there already set up to use the same skeleton. Like the animations I already have for the main characters I’m using for the player.

Infinity Blade Warriors.png

Among the many things Unreal Engine provides to help game developers get started if they need it is an asset from Infinity Blade the warrior's pack. Which are free to use for those who are creating a game in Unreal Engine. All of these creatures above have the same skeleton. Many of which can fit my needs.

The odd thing is nothing else was included with them. No blueprints, animations. Just there material files. That because you already have some of the basics to get a lot of things up and running with the basic Unreal Engine 4 starter.

I also found it somewhat amusing and at first thought they were broke. None of them appeared to have any working mesh collision until they are being controlled the right way. Being a total noob resulted in my attempts to fix things by adding collision. This also failed since I could still run through them. Thankfully I worked things out in the end.

Retarget Anim blueprint.png

Back to that starting Mannequin that I so forgot about. It comes with an animation blueprint and a decent starter State Machine as well. There is also this nifty feature called Retarget Anim blueprint which allows you to duplicate it onto another skeleton.

Feeling like a god it was time to see where else this could be used on. Now not everything follows this standard bone layout or even naming policy. Even among other humanoids models where you would think it would be.

Thankfully you can also under the retarget manager in the skeleton go down to set up the rigging and do some remapping. Where you are telling the standard rigging these are the correct bones you can map onto.

wrong bone.png

Well, that almost worked for this. One of this guy’s poor arms is twisted into his backside and just flopping around in other places where there is no longer a bone—oops. I thought this was the more horrific screenshot so it is the only one I took of this failure at using the remapping feature.

Still, not everything is going have the same bone placement so this only gets you so far. A lot of the stuff that comes with Unreal Engine 4 that you can get out of the store for free has some issues with it. For whatever reasons several of their animations don’t loop in place and I’ve yet to find a way to correct that myself. This is a bit problematic when I can’t import over ones already work since they have different skeletons. As the non-looping in-place animations ones can wrap around which reminds me of a few funny fails in a lot of video games over the years. No wonder they changed it at some point.

Basic AI

basic AI.png

In a couple of my first maps in my game, I ended up placing down several creatures. They have a really basic mechanic for their AI. They can take damage. They also drop items in a loot bag for the player to run over and collect.

This required setting up a character blueprint. Then selecting an animation blueprint, and which skeleton mesh to be used for the character and basic AI controller. I also modified information in a damaged blueprint I already had created for some earlier testing so they could take damage.

Unreal Engine 4 already has a component built-in called Pawn sensing. Which you can just add to the character blueprint and bam they can now detect you. Along with some other basic stuff like setting up navigation boundaries and some code to start wandering around and you are good to go.

Testing out AI.png

I am quite outnumbered in this screenshot above and they will chase after me. The issue is they were quite dumb. They can’t do anything fancy. Often they can get all clumped up if I have too many in a single area.

For a basic start and where my game currently is at. I find this to be acceptable for now. Heck, I’m quite certain I’ve played quite a few games where the AI was more or less this. There are some triple-A games even out there I swear they did not put more effort into it than I just did.

There are also places where I don’t need a lot of pathing logic like on the bosses the player fights in my arena maps. They can just stay put until the player comes within range. I don’t plan to add more depth to those boss fights until next year so they are good for now.

I could have stopped here and deployed what I learned and worked out to the 14 maps in my game at this time that needed creatures. It is going to take some time for testing, balancing, and a bunch of other stuff anyways. Many of which require more things to build out first and so I could have just moved onto getting a lot of things checked off my roadmap this week and saved the harder stuff for future passes and improvements to this system which I’m going need to do anyways regardless what I end up accomplishing this week.

I, however, wanted to see how complicated it would be to have a better system in place. How complicated could it get? Oh, it’s a lot to take in.

Advanced AI


a single task in the Behavior Tree.png

I had a couple of basic starting points but I’m just not that familiar so it was time to look into some basic documentation for Unreal Engine 4. After that, I turned to some online video tutorials and even checking out the Unreal learning center, Unreal examples, and whatever else I could to try and understand things.

I don’t have a programming background and while I have been using Unreal Engine for around 5 months now. There is still a lot I just don’t understand or even have tried. Unreal provides a few demo examples you can just open and see how things were done. Those, for the most part, were beyond my understanding when looking at AI and creature portions. They did quite a few complex things that I still am unsure of how they achieved them. I at least got some clues to where to start my search next.

I tried following along a couple of tutorials and most where quite bad. Many of them just flat out ended after a few episodes or an hour in and no further parts were ever made leaving you hanging. Others moved to fast with the person not saying what they were doing often making sweeping changes for “bug fixing”. Which judging by those comment sections I’m glad I skipped over those.

Unreal Engine 4 has a lot of parts to the puzzle when you want to create a better AI and how that character functions in-game. Just some of the things you could start including in this picture.

  • Behavior Tree
  • Blackboard
  • AI controller
  • Tasks
  • Decorator
  • Service
  • Arrays and vector points
  • Animation
  • Animation Montages
  • State Machine
  • Enumeration
  • AI Perception
  • Pawn Sensing
  • Pawn Noise Emitter
  • Stimuli sources
  • Debugging

The list could go on and on and on. The more I dug into it the deeper the rabbit hole went. At least armed with more information I ended up finding a decent YouTube channel called Ryan Laley with has an AI series going over more than I even wanted to know.

After trying out some of what he was doing I started making some small changes to make things work better for my use but kept a lot of his naming polices as it was just easier when I got confused about something to go back and see how he went about it. In the future, if I am going move forward with a more advanced AI for many of the creatures in my game I’m going have find a better way to scale and name things as there is a lot to take into account.

Not everything went as smoothly as I had liked but that is the nature of things. There is a part where everything just broke and that is where I ended up needing to take a step back. As this is quite the task to take on even with tutorials.

Tasks and Behavior Tree.png

Most of this is just for one creature. Kind of scary to think about. Took quite a while with a number of fails and issues along the way.

Behavior Tree.png

Thankfully most of it sits in the behavior tree so it’s easier to understand what is going on. I would not have made it as far as I have without following along to the many tutorials I did.

chase blueprint.png

There is stuff in there for focusing on chasing down the player like the above task. Then you have other tasks dealing with different situations like what happens after the player has escaped the AI. Along with setting up and even going back to the patrol route using arrays to store locations on the map.

I love behavior trees just for their organization alone. Everything is executed from left to right in mainly what are called tasks. It keeps going down branches depending on success or failure conditions set up in the code it is executing. You can apply special rule-sets to each branch called decorator or service.

If you decide you want to change the order of operation of something it is as easy as dragging one branch to where you want to be. If you need to add in loops or a branch cooldown to keep the creature it’s controlling from bugging out if things are running to fast you can.

I also know from more advanced setups I’ve seen that this is just scratching the surface. I have a feeling I could spend months if not longer just on this part of the game. There is just so much to take in and consider, test, fix, and try again.

The biggest issue I see right now is trying to scale things. Every example I’ve seen is always 1 creature running around doing its things. Try adding 50 into the mix and that is where you start seeing things break down.

There is also going be a lot of work to deploy this to all the different creatures I’ll be using in many of my maps. Quite a few different references need to be changed each time. While I tried labeling a few of them I discovered after trying to get this working on another creature that it was more involved than I was expecting.

Final Thoughts

Testing AI on test map.png

I’ll admit this ended up being quite a lot more than I was expecting to get into. It is tempting to dive into this for a few weeks just to be able to polish things up a bit more. Time restraints I have setup are going to prevent me from doing that. I should be able to do everything I want now and then some after I work out bugs and quarks.

I’ll be using both a mix of the simple AI and the more advanced one depending on the situation. Sometimes I just need a simple wondering around creature that might not always care what is going on. Other times the player will be facing something a bit cagier.

I had quite a fun time releasing a few creatures at once on a test map I have set up. It went better than I was expecting. Some things are already done. Others I’m hoping to implement over the weekend and maybe into early next week.

Other Posts:

Information

Screenshots were taken and content was written by @Enjar. Screenshots are from Unreal Engine 4.

Sort:  

Once you get used to setting up a roaming AI that can chase the player but also use animations and states for different things, it gets a lot better. Looking like you are learning quite well too.

My VR game I haven't done any on for a bit now, but it's still super early, but I made the pig I placed able to roam and moving with animation. When it dies it stops and the dying animation plays while not moving anymore. ... except randomly rotating 90 degrees about every 5 seconds, or just casting fireball a few times kills multiple I have placed in because bugs are fun! 😂

Undead pigs sound like a bonus feature! They are demon fireball casting pigs after all!

On death I just use DestoryActor for now to ensure total annihilation! I have been eyeing detach from controller though.

Haha yeah I thought about making the rotating pigs cast fireballs :)

Destroy Actor I had but I wanted the body to be left on the ground after a dying animation, maybe will make it so after a short time the body disappears too. Make it more natural for an RPG.

#posh for Friday!