Artifact of the week, AI.

Hello dear class mate(s).

This week I have been working with some simpler kind of AI. As always we have been using Box2D mostly for walls but that isn’t anything that I plan on rambling on every post about how it works, just so you know where the b2vec is coming from. 

Before  the feature freeze we decided that we probably should cut down on the number of enemies. We had four of them planned at that point. It is 3 and one of them is now a hybrid between a moth and a worker, so i refer to it as morker ^^ It starts as a worker, being passive until attacked. The next state is the attack states, and this is where it takes the ability of a moth. Only that moths were originally supposed to dodge every shot from the player and only be killed by a certain attack. The morker should only be to be hard to hit rather than impossible. We started with getting the morker to shoot since that felt simpler. 

We had the means to allow the player to fire bullets in the direction of the mouse. So to do this was not that different. The only thing that had to be done was to set the part that decides to fire to the mouse position to the player instead. It shoots right on point but it has some thing that might be considered as flaws. If you are moving constantly in a wide circle around the morker it will not be able to hit you. It is supposed to be more enemies in the game so you cant really adapt this tactic in game, but we might want to add some spread on the bullets so they are harder to predict. I think this is something that we might do a bit later though since it should work well without it too.

The thing that was more problematic to do was as to when the enemy should attack the player. At first I checked if the coordinates of the player was bigger than the enemy radius  to get the enemy to fire constantly to see if it worked.  This only works when you are moving in the screen though so it wasn’t meant to be a permanent solution. So next we added another circle to the enemy to act as range. So that if the player is inside that radius it will be attacked. 

bandicam 2014-02-27 23-04-56-501

 

Next we started on the moving part. We used a similar system from the cooldown of the bullets. A ticker counts down from 3 to 0 in very small jumps like 0.0005 and when it is between two values the morker is given a certain velocity. There are surely better solutions out there, but as fairly new programmers this was the best we came up with right now. 

bandicam 2014-02-27 23-01-05-476

 

The things we are doing right now is made in a “mock up project” since our main project is being re-built by our lead programmer. So if you feel like it looks too simple it might be because of that 😛 Anyway we will get the logic into the tasks so it shouldn’t be too hard to get it into the real project when it’s done in some days. 

Just a picture of the morker(white) shooting at the player. It hit as the morker continued upwards and so the player turned red.