Hey folks ! As some of you noticed, and told me, Wargame has somehow an Advanced AI, that reacts depending on the situation.
You will sometimes see enemies duck behind sandbags while shooting at you, throw grenades, and even PLANT MINES on the ground, as well as you will hear them call for backup, shot at you when they spot you, and call for help when they are hit.
They can navigate trough the entire map, without need to do anything from the user, they will go to the areas, stop there to capture it, and then go to capture your flag and bring it back to base !
How was that created? With Path Finder? No...Not at all !
Simply using Navigation nodes, now how do navigation nodes work ? What are the enemies movements ?
Well first of, the enemies and all AI in the game, use the MMF2 built in movement type Bouncing Ball...
Why ? Simply because bouncing ball is pretty flexible, the ball will keep going if the deceleration is set to 0, it will change its direction like you want, and will stop when you want, it's the best available movement in MMF2, I use it for particles, smoke and a lot more !
More advanced users will tell you to create your own movements with X and Y position, this works as well ! But Bouncing Ball is really good and flexible !
I got
Right Node
Left Node
Climb Node
UpDown and Right Node
UpDown and Left Node
Down Left/Right Node
Enemies Camp Node
Dismount Node
Diagonal Up Left Node
Diagonal Up Right Node
Diagonal Down Left Node
Diagonal Down Right Node
Nodes are simply active object, 32x32 active boxes, that you can draw any color you like, and put a little text on them to let you know quickly what type of node it will be.
So simply, this is how the nodes work :
Enemies spawn : set direction to left, start movement
When enemies Spawn, they go Left and start walking, simply because they are at the right end of the map, so the only direction to go, is left.
Collision with Right Node : Set direction to Right
Collision with Left Node : Set direction to Left
The right and Left nodes have to be placed at places where there is ONLY ONE direction available, for example at the end of the map, or if there is a wall near it, so that when the enemies get there, they don't keep walking trough and leave the frame.
Collision with Climb Node, While Facing Left: Set Direction Up, Left; set Flag 1 on
Collision with Climb Node, While Facing Right: Set Direction Up, Right; set Flag 1 on
Now, this is where it gets tricky, but don't worry it's simple enough !
Basically, when enemies hit a climb node while facing left or right, they will set their direction, either UP, or they will keep moving in the direction they were facing, so the AI will randomly choose between theses 2 directions.
Now what about the flag 1 ? Well it's simple, just take a look at this condition :
Is Flag 1 Off, and Character Moving Up : Set Direction to left
Is Flag 1 Off, and Character NOT Overlapping Backdrop : Set position one pixel down
So basically, the Flag 1 for movement will be the flag that tells the AI he is climbing, if this flag is set, he will be able to move up, if the Flag is Off, each time he tries to move up, he will be redirected Left, and if by any miscalculation he finds himself not overlapping your Frame's backdrop, he will be moved one pixel down until he is on the backdrop. But when the flag is On? Then how do you turn it off ?
Collision with UpDown Right node while facing up: Set Direction to Up or Right
Collision with UpDown Left node while facing up: Set Direction to Up or Left
Collision with UpDown Right node while facing left: Set Direction to Up or Down
Collision with UpDown Left node while facing right: Set Direction to Up or Down
Collision with UpDown Right node while facing Down: Set Direction to Right or Down
Collision with UpDown Left node while facing right: Set Direction to Left or Down
Now that's a lot of events...So what happens here? Well the UpDown Right node is the one you wanna set up at each floor the ladder gives access to, because the character will go either down to first floor, either up to the next floor, or will go on this floor.
Collision with Down Left/Right node while facing up: Set Direction to Left or Right
Collision with Down Left/Right node while facing left: Set Direction to Left or Down
Collision with Down Left/Right node while facing right: Set Direction to Right or Down
Now this node is the one you want to place on TOP of ladders, when character have finished climbing, he will go left or right, and if he goes on the ladder from the left or the right, he will either keep going, or climb down.
So now we have made an event to make characters either start climbing on keep walking.
An event to make characters either stop climbing and get to the floor, or start climbing up or down.
And one event to make characters stop climbing and go left or right.
But we have one left to make ! What if characters climb down, they will not stop we have to make it that, if they touch the first climbing node while going down, they will go left or right.
Collision with Climb Node, While Facing Down: Set Direction Left or Right; set Flag 1 off
Now the loop is almost complete ! Characters will go up, down left right on your nodes ! But we must complete one other thing !
The dismount nodes ! You see, when Characters hit your nodes, they will randomly go in a direction, but you can't tell if they are going to keep climbing or not, so you can't set the flag 1 off (climbing flag) at any of thoses !
That is why you need a Dismount Node.
The dismount node is special, because it needs to be as Tall as your ladder ! That's right !
Why? You might wonder ?
Well because, its either you place one 32x32 dismount node near EVERY possible dismount position, which would make 2 nodes per floor, or you put one tall node next to your ladder, that makes the characters get their flag 1 off when hitting it.
If Flag 1 On; Collision with Dismount Node: set Flag 1 off
Tadaa ! Characters will now climb ladders the right way !
So that was it for ladders ! But what about diagonal stairs? Then use the diagonal nodes, they work the same way, but with diagonals !
Collision with Diagonal Up Left Node : Set direction to Diagonal Down Left, Set Flag 1 on
Collision with Diagonal Up Right Node : Set direction to Diagonal Down Right, Set Flag 1 on
Collision with Diagonal Down Left Node : Set direction to Diagonal Down Left, Set Flag 1 on
Collision with Diagonal Down Right Node : Set direction to Diagonal Down Right, Set Flag 1 on
Then you have to put dismount nodes at both ends of your stairs, but you need one more event if you are using diagonal directions !
Collision with Dismount Node while facing Diagonal Up Left: set direction to Left
Collision with Dismount Node while facing Diagonal Up Right: set direction to Right
Collision with Dismount Node while facing Diagonal Down Left: set direction to Left
Collision with Dismount Node while facing Diagonal Down Right: set direction to Right
Now you have to tune this very carefully ! The diagonal direction needs to be an exact match for your stairs, or your characters will either fly above your stairs, or climb to low on your stairs.
Also, in the collision with dismount node event, the diagonal left direction has to be the exact same as the one your character will be going in ! So tune it right !
So that was it for the stairs and diagonals !
Now what about the Camping Nodes? You might think they are not important ! But trust me ! Having enemies walking around and just shooting at you non stop, tends to look stupid !
Having camping nodes around is important ! How do they work ?
Simply place them behind obstacles, like sandbags, or debris, or anything that is set up to destroy bullet on hit, so it is a proper cover.
On Collision with Camping Node and Alterable Value A of Camping Node=0: Stop, Crouch (if you have a crouch animation); Add 1 to Alterable value A of the Camping Node
Now what about that ? Well its simple, if a character hits the camping node, and this camping node's alterable value A is 0, it stops the character there, and sets the alterable value to 1, so this way not 2 enemies can camp on the same node !
Then what? Will he stop there forever ?
Alterable Value A of Camping Node is Greater than 0, Every 1 sec Add 1 To Alterable Value A of Camping Node
If Character is Stopped, and Character is Overlapping Camping Node, and Camping Node Alterable Value A is over 5 (or the amount in secs you want the guys to camp) : Character Start Movement
What did we just do ? Well, when an enemy starts camping, the alterable value a of the node will add 1, and when the value A of this node is above 0, it will Add 1 to it every 1 sec.
Then, if the player is stopped on the camping node, when the Camping Node's value is reaching 5, or 6 the Character's movement will start, and he will stop camping.
Now that is good, but then no characters can camp again on this position, since the alterable value is not 0 anymore, well there is a simple solution to that.
When Alterable Value A of Camping Node is Greater than 10, and Character is Not Overlapping it, Set Value A to 0
Now what did we just do ? Well, if the character is on the node when the node's value goes back to 0, he might just sit there again to camp again, since he is told to go and camp when the value is at 0, that's why we have to set that the value sets to 0, a few seconds after the character has left !
For example :
When Val A = 5 Character Leave
When Val A = 8 Set Val A to 0
This is pretty simple ! This is an easy way to make your characters camp on nodes, and then make the node usable again soon after the guy left !
But with this technique your characters will Always camp on the node when they hit it, which can get sometimes pretty strange, if you want to avoid that, just set that the value of the node goes back to 0 when it reaches 20, or 30, this way the enemies cannot use the node again for 30 secs.
Well that was it ! I hope you have learned a few things ! Any comment or suggestion are welcomed !
|