I know this will obviously take allot of skill but has anyone achieved to make an Enemy AI using MMF2 or TGF2? I know the extent of the AI will be limited but I was just interested to know if anyone had achieved this.
Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.
A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.
Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!
Clickteam.
A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.
Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!
Clickteam.
-
-
I think anyone that's made a game with MMF2 has made AI for enemies. Can you be more specific. What genre of game are you making?
-
And what would you consider AI? In game terms it's already considered AI when the enemy can shoot at the player on sight.
-
There's entity AI and "enemy player" AI. The first is easy, and is as simple as "Distance less than 200, look at player and fire gun".
"enemy player" AI is things like a strategy game opponent. These are nearly impossible to create, even outside MMF.The difference is that entity AI is essentially reactive, it only reacts to things happening. "enemy player" AI can make some of its own decisions.
Some AIs made in MMF are impressively complicated.
-
Generally I tend to use random variables to decide what my enemies do. It makes them difficult to predict.
-
I use states, so my AIs are more like state machines I suppose.
The way I figure it, you've got a better brain than the machine, so you may as well give the AI as much help as you can!
The trick to state AI is to give the enemy player as many senses as possible. So by senses I mean events that tell him something practical about his environment.
So for example, I want a platform AI who chases you and leaps off ledges if he can, but screeches to a halt if he can't. How do we code this?
We give him a simple set of tests. So for instance, I put a detector about 40px in front of him. If it stops overlapping an obstacle (the floor), then the enemy has got a drop coming up. When a drop is sensed, we test again to see if the drop is 30px deep (a safe falling distance). If it's still there after 30px, we either move it downwards to see just how far deep the trench is, or simply tell the AI that this edge is BAD.
The AI stores this in one of its many Alterable Strings. It now knows to apply the brakes because even if the good guy leaps off this ledge, it won't be safe for the bad guy to do so.
We can extend it by using still more detections, so for instance I know when he jumps he has a force of -10px, and gravity is 0.3px per second, and his forward run speed is 3px, so I can plot his jump curve. Using this data, move a detector along that curve and if it lands safely, you know he can jump the gap.
You can basically make it as complicated or as simple as you like, but this still comes under what Dynasoft described as Entity AI, rather than a convincing opponent.
For most of our games though, Entity AI as described above is sufficient.
The key like I said is perform lots of different tests and store the results in alterable strings and values. Is the NPC standing on the floor? Is there a wall to his left? To his right? Above him? Is he coming near to a ledge? Is that ledge dangerous? Can he jump the gap? Does he have any weapons? How much ammo? Are there any friends nearby? Is there anywhere he can hide? How close is he to the player? Is he facing the player? You just have to ask the right questions for the behaviour you want to simulate.
Then, when you've checked all these details and stored their results in his memory, you can now make decisions using them. So:
NPC is standing on floor
Has Javelin in hand
Player is in range
Path not obstructed
--- NPC: Throw javelin.NPC is standing on floor
Has NO javelin in hand
Player is nearby
Friend's corpse is nearby
Friend's corpse has javelin (left on floor when he died)
--- NPC: Run to javelin(the NPC will now pick the javelin up, so the event above will trigger and he'll throw it).
That's how I do it anyway, you can give him all sorts of responses this way, and factor in unique features thanks to MMF's new 'x in y chances' feature.
-
Quote from Dynasoft
There's entity AI and "enemy player" AI.
You just made that up to sound smart, right? Sneaky.
Nice breakdown, Dines.
If you want to have your NPC make "intelligent" decisions, you have to provide as much information as possible - within the limits that the NPC can perceive. Having your NPC not know where the player is until he actually sees the player is pretty nice in most games (and can make some tasks easier - e.g. you can get away with less navigation / pathfinding if the enemy does not approach the player if he can't see him).
On the other hand, if you can make good use of a pathfinding extension, you have one of the trickiest parts of AI already nailed. E.g. for strategy games Greyhill's Advanced Pathfinding Extension can handle A LOT of AI issues. -
Gotta mention one thing about pathfinding though... What most people consider "good" pathfinding is when the enemy can find the shortest route through a series of obstacles to get to the target. This is actually BAD. Why?
Because much like a hamster in a maze, an enemy is not going to automatically know the shortest path and then take it. That isn't realistic at all.
A better approach would be to have the enemy take what it THINKS is the shortest path, based on how close it is to a path, how long the path looks, etc. For example, if you were in a maze and approached a fork in the path, would you take the short path that turns early, or take the longgggg path that has multiple turns at the end? You'd take the short one, because you'd mostly likely find out quicker if that way is a dead end.
But a "good" pathfinding AI would determine that the long way might be best, if it is indeed shorter. So it would take the long path, which defies human logic.
So I'm all for making enemy AI sort of "stupid" when it comes to pathfinding, and giving them the ability to get lost or trapped or what have you.
This won't work in all games, mind you, but it's worth a shot. It really wouldn't work in Pacman, seeing as how the ghosts need to be able to hunt you down with a high degree of speed and accuracy. It's not as though enemies can see the maze from a top down view and plot the course accordingly. All they'd see are walls and openings.
Of course, one has to wonder why ghosts even need to pathfind when they could just go through walls... which makes me wonder why nobody thinks about this when playing Pacman. :p
-
I think that's a very interesting point, but really only applies in some situations. In many games you, as a player, would expect units to see the world as you do - top down, or whatever it is.
Especially if they're YOUR units in an RTS, or YOUR character in any point & click game.So often enough, this level of realism is bothersome for the player, or he doesn't really care anyways. It is a thought that becomes very apparent to you as a designer, but most players wouldn't notice the extra mile you went for more realism.
The same is often the case when you make some elaborate choice system vs. random choices.
For most players the random choice will just do fine. -
Someone should upload an example, at least a little enemy, because I can't imagine doing that.
I don't know how to use timers, I found them useless (in MMF2).When I hacked SMW, what I did for enemys was define some kind of variables that were the timers, and the enemy do a different action each specific time.
So, for example, what if I want an enemy that always faces the player, and each 1 second or 2, throws a bullet?
Another thing is bugging me is the problem of insert 2 or 3 enemys of the same.
Let's say I make an Active Object, that is name Enemy1.I set up a timer for Enemy1; each 3 seconds throws a bullet; the enemy always faces the player and it have an Alternate Variable named HP, that contains 3. Each time the player shoots towards Enemy1, HP decrease 1, so when HP = 0, Enemy1 is destroyed.
I insert Enemy1 in the frame and it works well.
I want to have 3 Enemy1 in the same frame, so I make copies of it. That's where the problem is. There are 3 copies of the same Active Object.
If I want to have 5 or 6 Enemy1 in the Stage, it's useless to make 6 Active Objects with the same settings.
I hope I explained myself well hehe.
Thanks.
-
Well that's kind of where MMF can get a bit nasty, but it can be done, no problem.
To have multiple instances of one object, there are different ways to handle it. For one, never make copies of the enemies. You don't want to have duplicated code.
You have to learn and understand MMF's selection system. Most conditions of an object make a selection.
E.g.: + Alterable variable "HP" of "enemy" < 0MMF runs through every "enemy" object and checks for that condition. It then removes all objects from the selection that do not meet that criteria and goes to the next condition,
e.g.: + Animation "exploding" of "enemy" is not playingNow it picks, from the objects with HP < 0 those that dont play animation "exploding". And then you add an action:
> "enemy" > play animation "explode"This action will be executed for all "enemy" objects in the selection.
As you can see, having multiple instances is no problem here.
Speaking of your timer - just use an alterable value for that, that you increase for all "enemy". E.g.:+ every 0.1 seconds
> "enemy" > add 1 to alterable value "shoot timer"+ shoot timer > 2
> "enemy" > subtract 2 from "shoot timer"
> "enemy" > shoot at playerNow there are certain circumstances, where this system won't cut it. Especially if you need to associate the object with other objects (e.g. collision sensors, attached objects, etc.).
That's where you use the "spread value" function with 0.+ Always
> Spread value 0 in alterable value "index" of "enemy"Now you can run a loop over all enemy objects, using that value:
+ Always
> Start loop "enemyLoop" for Count("enemy") times+ On loop "enemyLoop"
+ alterable value "index" of "enemy" == LoopIndex("enemyLoop")
+ "enemy" is facing left
> "enemy" > set position X = X("enemy") - 1+ On loop "enemyLoop"
+ alterable value "index" of "enemy" == LoopIndex("enemyLoop")
+ "enemy" is facing right
> "enemy" > set position X = X("enemy") + 1I hope that clarifies things a bit.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!