Tuesday, August 22, 2017

Week 10 - Finite State Machine (FSM) GAM111

LECTURE:
What are Finite State Machines? A finite state machine is a system in which most companies would use for a basic AI system. It can also be used to keep track of what state a game is on, and even more! But during this lecture, we learning on how we can use an FSM as an AI in any project.

The concept of an FSM is to have a finite number of states, with a set of transitions between them. So if we were to make an enemy, we would give the enemy about 3 to 4 states. An idle state, patrolling state, attacking state, and a chasing state. Each state would have a specific logic written for them. So, to make a variable containing all these states, we write something like this:

Enum enemyState state {Attacking, Idle, Patrolling, Chasing};

Enums or enumerators(ions) allows you to create a collection of related constants. In this case, we are creating a collection of states for the enemy AI. Alongside this variable, we also need to make a current state, where it would set the default state, so something like:
curState = enemyState.Patrolling;

An FSM is sometimes followed by a switch case statement. This is where the transitions between each state happens. So if the player was in a certain range to the enemy, the enemy will then change to a state called Chasing (this is not how you would write it, this is for example sake only):
if (the distance of the player is > 40m) #This is where the logic will be written
{
    curState = enemyState.Chasing # This is where the transition between states would be
}
And if the player is closer to the enemy, the enemy would start to attack. So we would write the logic of the attack, and change curState to enemyState.Attacking, and so on, and so on.

SETBACKS:
I am still having troubles with the turret logic in the game, and it seems as though that I am at a stalemate with the turrets. I'm not gaining anything, neither am I losing anything. I keep on finding myself at the same spot.

ACHIEVEMENTS:
For this weeks achievements, I have:
I managed to get 3 enemies with different attributes. One small enemy (weak but fast), medium enemy (decent speed, decent health) and a big enemy (slow but deadly and "tank-y")
I managed to get a healthbar, for the base, and the enemies. Before this, the one type of enemy I got was a one-shot-one-kill enemy
I managed to get a basic UI system where it notifies the player when an enemy will spawn in

MILESTONES:
My milestones for next week are:
To finally get the turrets to work
To critically analyse if there is anything else I can add to make the game better
To find some assets in the store to make the game look better, other than using bland texts and/or blocks







No comments:

Post a Comment