Makng AI thats FUN to fight

I do have to say before I start this the reason why they just wiggle around once there in the blue circle is because I just make them do random movements once they reach their objective. im not finished with that part. The combat part however is 100% finished.


Here it is. The NEW and improved AI engine. Its all powered by ONE SCRIPT, all you have to do is place your humanoid in AIsquad1 and the script in serverscriptstorage will give it all its attriubtues, apply humanoid onchange events and more to it. Meaning you can ADD ai just by cloning a normal humanoid from replicatedstorage to workspace.Aisquad1, (There are multiple AI squads you can add in workplace) they can even fight other humanoids in the same aisquad provided their team attribute is different,

But lets go in to WHAT these ai can do.

Movement During Combat with the player/NPCS they can do

They can Strafe
They can Strafe Fire
They can move away from the player
They can charge towards the player in a rage.

Actions they can do during Combat with the player/NPCS they can do

They can Taunt the player


They can ragefire when low on health which means they fire faster
They can do a calculation to get the closest allys and tell them to come over and assist.
If you WANT they can do a FLIP/Evade move

They REACT when damaged and will do actions like

Strafe away from the player
Ragefire
Strafefire
Call their allys for assitence by getting the 3 closest allys provided to them.
React with multiple different animations to indicate damage

They also have a voiceline system where they can react based on

If there wounded
If they need assitence
Taunt and general lines.

which of course can be customized.

The cooler thing is that they can also attack humanoids that are NOT in workspace but rather inside another model.
SO for example if a humanoid is in Workspace → RandomModelName → Acutual NPC Model
They will still attack and damage them.

What makes a GOOD ai

This is a question that I thought about answering. In alot of games AI kinda sucks, Cod is a GREAT example of this. The enemys have no behavoirs other than shoot, take cover and very basic things that make it a forgettable grindfest.

Call of Duty: World at War(2008)

I hate AI like that, AI Where every enemy acts and behaves pretty much the same. If you played any of the Grand Theft Auto games you also know what im talking about.

Now lets talk about what makes good ai, For this example were going to be taking a pick of a game KNOWN for its groundbreaking AI. Halo Combat Evolved(2001)

There is a GREAT video talking about AI in the Halo games that I recommend you watch
The AI of Halo 1 Combat Evolved | Design & Implementation - YouTube

My favorite thing about the AI in halo is how they have personality
For example, Elites in the game are the aliens that are the equal to the player they are strong, brave and dangerous , But they have personality not just in their dialogue and design but also the way that they BEHAVE

For example if you stick a elite with a plasma grenade it will ALWAYS run towards you and try to kamikaze you

When spotting the player they will Taunt them and get angry, they don’t just instantly start shooting.


When you try to run them over they will go to dodge them. so you have to time your car or do a drift

Lets look at the grunts the little guys, These are the weaker enemy’s that come in pairs, and even the weakest enemy’s in the game have more behaviors and actions than most triple A games today

When they get hit with a plasma grenade they will run to there allies for help taking them all out

SOMEONE HELP ME I HAVE A GRENADE ON ME

When there leader(Elite) is killed they all start running away in a panic

LEADER DEAD RUN AWAY

They will try to always stay together as a group and work in numbers


And so much more that I’m not going to bore you with the details. If you want to see the design process for advanced AI that is ACTUALLY good then I highly recommend this video.
The AI of Halo 1 Combat Evolved | Design & Implementation - YouTube

But you notice something about this, They don’t just have personality in their voice lines or art design, But in the the way they BEHAVE. They are not just some mindless drones like in most triple A games but have patterns, behaviors and more that make them unique and fun to engage with. This is what I consider GOOD Ai, Ai that has behaviors and patterns that give the enemy’s personality, diversity(I hate the word diversity to ok), and depth.

My orginial design for the AI.
Before I talk about my plans for the future I want to start with my very first design of this AI system about 2 months ago. No i haven’t been working on this for 2 months more like 2 weeks or so.

But originally I designed a behavior document to first outline how I was going to implement such a monumental task.


If you go and read it you can tell its very barebones, Bad and basic.
Eventually I did implement the first version of these ai which you can view over here

These ai did not disable Humanoid AutoRotate(Humanoid | Documentation - Roblox Creator Hub) So they never properly faced the player,

They also NEVER responded to damage which I later did add but did it in the worst way possiable.

In order to CALL in a new ai and have it respond to a health change event I made it so that you had to fire a REMOTE event once the ai was called in for EVERY SINGLE NEW AI that was not orginally in AIsquad at the start.


OOF.

They also did not clear themselves on death.

But they did have Squad mechanics.

Eventually I went and redesigned them to properly handle stuff and took away notes for how I can make the NEXT ai unit better,

for the next AI I wanted them to dodge and flip, Orginally I applied a Vectorforce that did not work, and they would also DODGE while taunting the player creating issues.
But for this version I made them react to damage and taunt the player. This is a early version for what would eventually be used for the second AI unit in the game

I also used Childadded instead of requiring ANOTHER remote event which yes I still regret being that stupid in the first place for not using childadded
These were the stepping stones for the final version of it.

Plans for the future
Make it multithreaded

Currently the New ai system is GOOD but im suffering from success,
I want to use multithreading but im not sure where.
MULTI-THREADING on ROBLOX?! - YouTube

For those who do not understand multithreading multithreading is basically splitting the work of code via multiple CPU THREADS.

So for example instead of doing

Thread 1: Task 1 → Task 2 → Task 3


We can do
Thread 1: Task 1
Thread 2: Task 2
and Thread 3: task 3
all at once
Problem is that multi threaded code on roblox Can not access ANYTHING in workspace or check attributes or anything. its purely for LUA code without all the roblox libarys and stuff. think like math.sin or math.random or for statements, that sort of thing, things that can be done in basic lua.

The good news is that you can switch between multithreaded and in sync code at will in roblox
the bad news is that I use attributes for the ai units and others that cant safely be accessed in multithreaded mode. And I COULD change the system to maybe take in the attributes of newly added AI once in sync mode and then store it in a array for the multi threaded part so I can safely access it, BUT that means that you won’t be able to change the teams of the AI once added to the aisquad of your choice in workspace. And on top of that viewing attributes is such a small performance loss that making that part multi threaded(Which by the way is pretty much the only thing I can largely change to be multithreaded considering most of the ais logic is based on things that require access to other services and parts that are not safe in multi threaded mode.) That it might not even bring that much of a performance boost, even worse it might result in WORSE performance having to switch between multithreaded and non multithreaded.

Adding more events for AFTER the battle is over
I plan to add more events that the AI can do AFTER the battle is over. For example a couple of them are

Sometimes after killing a body the soldier enemy type will go and get up to the body of the enemy and shoot the dead body to show that they one. Like a “You better stay down” moment

Sometimes if close to the player they will stare at them not moving and say a voicelines but not General lines, rather a NEW catagory of lines for the AI AFTER the battle has ended that will be of course catagorized like every line.

Do a standard taunt.

Go and regroup with the main squad if far enough away from them with a magnitude caluclation

13 Likes

Before Sending a AI model into workspace.YOURAISQUAD model you can also customize them with attriubtes that the AI scirpt will respect

like their Team, Parent, and also Objective(Ie place they need to defend if needed)

1 Like

This looks really cool. How can I get it?

I don’t plan to share it JUST yet. I still need to handle what to do once they reach their objective rather than just sit and run around in random directions

True, good luck on the project!

1 Like

orginally these ai were very barebones. just look at how unfinished they were a month ago

4 Likes

glistening gemerald of an AI, when will this game release

2 Likes

Soon. As soon as I finish some bugs with the casino and kingdom of science for the game

2 Likes

Wow, this is cool.
This is like a SWAT team.













(soyjak warfire against trolls)

2 Likes

“nothing ever happens” ahh face :pray::cl:

2 Likes

where do you get the CL emoji lul :pray: :pray:

2 Likes

windows button + . i didnt know what emoji to put so i just put that :no_bicycles::pray:

3 Likes

This realistic AI is INSANELY good and cool! Nice job on it! How long did it take for you to make this AI? When will you finish it fully? This is crazy!

In terms of time about a week, maybe 2. I started it 2 months ago and then updated it in June and then finally made the final changes today.

About 2 weeks.

Im not going to publish it for a fee beause im not one of those types of devs.

But First I want to get my game done first which is like 98% done

I added more for people who want to make there own vesrions of this and what makes good AI

1 Like