Week 7

Did not do much this week. Was incredibly slow.

I mainly just worked on my essay.

I have been tasked to start the works on the audio for the game, which is quite nice. It is going to be fun. Plus, soon hopefully the skills can be implemented into the game, as well as the models, animation and environments.

I did some research into an interactive narrative, and it does not look too difficult to implement, so it should be fine.

I am just gonna focus on my essay this week.

Week 6

Monday was something.

We learnt about QA testing and how to approach it. So, for our game we had to split it up into various sections of the game. For example the battle system, UI and characters. This then get split up into even more parts, all testing various parts of the game, both interactable and noninteractable. So, both gameplay and visuals.

This part did take a long time, but it did address a lot of things that the game should have in this vertical slice.

After that, I was with James to do more coding. We were able to showcase the range by using a circle instead of a sphere, which was quite cool. Then, after that…

We decided to make halo’s and lightsabers, cause bloom is real cool. I have now decided what I am making next year. It was a very hectic afternoon.

Prototype

In my own time, I try to prototype some of the mechanics myself so I can better understand on how to code it. It is quite fun to prototype, so on this post I am just going to write about and upload the prototypes I created.

The first prototype I created was the grid movement for the battle system. As can be seen in my research post, I followed a tutorial on how to create it. It did take some time, but it was enjoyable to see it come together. It also includes an AI which goes towards the player every turn. It is quite cool.

In the same prototype, I also experimented with a shop system in the game. This was mainly to do with UI . However, I was able to create a scrolling system for the shops. Once I have the base design done, it can be replicated to all the other shops.

https://1drv.ms/u/s!Av0ESYUkDx81gZogr7625Ky0SIQA2A?e=upcHnZ

OneDrive link! Wooo.

Welp, cannot use OneDrive anymore…

So, I am going to try to upload all the versions of the game here.

New link!

Research

At the beginning of the project, I knew there were a lot of things I do not know how to do. I split it up into a list:

  • Movement
  • Turn Based System
  • Shop System
  • Skill Tree

So, I started my research on the movement. Since the GDD says it will be a grid based system, that is what I researched on. There were a lot of tutorials online for a grid based movement, but for me this one was the most useful.

Playlist on grid based movement

I was able to follow this tutorial quite well, but the problem is that the person who created this tutorial did not finish the playlist. So yeah, that is a problem.

So, I decided to move on to the shop system. Since the game will have customisation with weapons and clothes, then obviously I had to learn how to create them. I have not completely finished following this tutorial, but from the looks of it, it is not that difficult once you get the foundations done.

It is quite nice and easy to follow, and I was able to prototype this a bit.

Long videos, but useful

After that, I started my research on a turn based system. Honestly, it was not as difficult as I thought it would be. I pretty much only followed this one video for it.

Easy

Now I am going to start my research on how to create a skill tree.

AI FSM Actions

This is where the actions the AI can make. It is quite long. Enjoy!

First thing, it will call the NavMeshAgent in the void Start function. We will be calling it nAgent, so it is easier to type.

The first action that the AI can do. Moving! Specifically towards the closest player character.

We will be calling the game object p, for closest player, and v, for the distance between the AI and player. It will then determine how far they can travel by using the the AI move stat and the distance. If the AI is already close to the player, so the percentage is above 100%, it will only go up to 80% of the distance.

It will then target which player they will go towards, by determining which is the closest to said AI. Once it has determined that, it will set its destination towards set player.

This function is pretty much the same as above, but will instead go the opposite direction of the nearest player.

So, how does it determine the closest player? With this function. That is how.

It will first get all the game objects that has the tag “Player”. We then say, this player will be known as “closest”.

Then it will determine the distance between the AI and all “Player” objects. So, for each “Player”, it will compare the distances between all of them with regards to the AI. Which ever has the shortest distance will be known as closest. So, there you go dudes.

This is where the AI can attack the player. It will be using the stats from the AI, using hte range, accuracy and damage.

It will determine the closest player. It will then use the same accuracy script like in the Player Actions. So, by using the accuracy, it will get a random number between 0 to 100, and if it is lower than the accuracy stat, it will hit. It will then damage the hp, using the Alter HP function. If it is not, then they will miss.

Nice!

AI FSM Manager

This is the manager for the AI. This is how the AI will act in the various phases in battle.

So, first it will call the AIFSM Action script for the actions they can do. It will also call the Character stats, since that is needed to know the accuracy, range, damage and move.

So, when the game starts, it will call the these two scripts. We also simplified the name for both scripts so it is easier to type.

Then, during the attack phase of the battle, it will call the stats of the enemies, which are the range, accuracy and damage. Simple.

So, absolute unit of a piece of image. Like, look at that. Wow. Looks long. But nah, its not.

As can be seen, the hp stat is being used to determine how the AI will act like. As an example, at the top it says if the hp is above 90, then they will always move towards the nearest unit. Then, if the hp drops between 89 and 60, that will change. There will be an 80% chance it will move towards the player and 20% it will move the opposite direction. Same with if the hp is between 59 and 20. The chance it will move towards the player is 60% and them retreating is 40%. When the hp is lower than 20, the chance it will move towards the player is 20% and them retreating is 80%.

So, the lower the health of the AI, the more defensive it will act. When on really low health, it will pretty much keep running away since the percentage chance is so high. However, there is always the chance it will move towards the player, like a final showdown.

Character Shoot Code

This code is how the characters will shoot and apply damage. Lets get straight into it!

So, the first thing here is that the code is calling the CharacterStat script and the game objects. Since we need the character stats to indicate whether the opponent is within range.

Then, in void start, it will immediately call for the stats for the range of the characters.

In void Update, every frame it will check whether the player has pressed the left mouse button. If the player has pressed the left mouse button, it will start the GetShootTarget ting.

So, the same as the character movement script, a ray will be cast from the camera. It will track the mouse position on the screen. If the mouse is clicked on an object that has the tag “Enemy”, then the target will be that game object. It will also say Target Spotted!

This is where the ApplyDamage is. Pretty much, when the target is picked, it will check whether the distance between them and get that distance. It will then check whether they are in range of the characters.

THEN, it will use a random number between 0 to 100, using the accuracy stat, to see whether they hit or not. If the number the computer gets is less than or equal to the accuracy stat, then they will hit. When hit, it will alter the hit points of the enemy depending on the weapon damage. If they miss, then that is that. The console will say I missed!

Quite fun stuff

So, I made one small change here. I added the current amount of attacks statistic, so that the function is called multiple times until all shots of the weapon is fired. Everything else is the same.

Team Manager Script

This is the longest script at the moment out of all the other scripts. This is gonna be fun to talk about!

To start off again, here are the variables which will be used. So, the first part is it will be calling the game objects that are teamMembers and enemies. Nothing too difficult. The next is an int that will keep track of the current turn the battle is in.

Two materials will be called, one that is for active and one that is inactive. This is so it is easier to see whether a certain character will be making a decision or not.

Finally, the UI will be called, specifically the turn button and the buff panel, for now.

So, an easy start!

At the start of the game, the script will call for objects which has the tag of Player and enemies. It will also disable the buff panel since it will not be in use on the first phase.

Now, something that is honestly, very difficult to understand.

This line of code. Oh my. OK.

Pretty much, if you click on a character, it will set them as active.

Wow.

Insane.

Well, actually not. It will call the SetActiveMember, which is the next piece of code!

Wow, it is SetActiveMember! Was it a journey to get here? You need some refreshments? I shall provide. Don’t worry about it!

Now, this will cast another ray from the camera to wherever the player’s mouse is pointing. It will then call the HandleMemberSelection. Which is the next part! It is like I planned this. Damn.

Now, this is a chonker, but honestly, it is nothing too difficult. Once the HandleMemberSelection is called, this piece will activate.

The first thing it does is that it will change the isActive boolean to true for the selected character, as well as apply the material activeM. This way the player knows that this is the character they selected, and it can be moved.

Then it says, if the teamMembers is not active, it will run the next few lines. If it is active, then it will break

So, if it is not active, it will change the isActive boolean to false. It will then check if said character has made a decision. If it has not, then it will change the material to inactiveM, indicating that it will be doing nothing.

This part though. Oof. It is something.

All it does is increase the current turn by 1. The next part then says that once the number hits 3, it resets back to 0. So, the turn counter is 0, 1 and 2. It starts at 0.

Alright. Here comes the first part of the actual turn based system. Or is it?

Anyways. As I said before, the counter starts at 0. So, on turn 0, the CharacterMovement script will be enabled and the CharacterShoot will be disabled. It then breaks.

On turn 1, the CharacterMovement is disabled and the buffPanel is now active. The it breaks.

On turn 2, the CharacterMovement is still disabled, the CharacterShoot is enabled and the buffPanel is disabled.

Quite simple.

This part literally says what will happen during the attacking phase. So the players characters will be able to apply damage, and the enemies AI for attacking will do their attack as well. It then says that the button will change it’s text once it is clicked. It will turn to the next phase.

For now, we have not included any buffs for the characters, so there is only a debug to say setting buffs. The player clicks the button and the text changes again.

Same as the attacking phase, the character movement will occur, as well as the AI movement script.

Same as before, click the button, and it changes its text.

The final part! Yay!

All it says is what each turn is, and what is done in each turn. For example, in turn 0, the MoveAllCharacter part is active, then breaks. Same with turn 1 and 2. It also increases the counter each turn.

Character Movement Code

At the top, it references the stats from the Character Stat script, so it will be using those stats. As well as a boolean for moving, to state whether the character is moving or not, true or false. Next it references the the NavMeshAgent as nAgent, so it is easier to type. Finally, there is the two different positioning utilising Vector3.

The next part is about making the decisions, since it is a turn based game. There are two more booleans, stating whether the character has either active and if it has made a decision.

Then it references the material which will be applied when the decision is made.

This is what will be called at the start of the game, which is the position of the characters, the character stats and the NavMeshAgent. Nothing to complex.

Every frame, the game will update and check whether these things are true or not. So, the first thing it will check is whether the character is active or not. If it is, it moves on and checks whether it is not moving. If it is not moving, then the player will be given the option to target the character they want to move. If they are moving, they they will not be able to.

So, to actually target a character is this part of the code. A raycast will be sent from the camera. It will then use the mouse position to see where it is on the screen. If the player presses mouse button on top of a character, then it will call HandleInteraction.

This is the HandleInteraction part. It describes what happens when the player selects a character. So, when they do click on a character, the switch statement activates and goes through the case. The next part is pretty much, when the NavMesh is is clicked on again, it will select that position. It will then say to move to said position. Then the material for decision made is called, and applies it to the character. This will then turn the haveDecision boolean true. Once it is all done, it breaks, ends it.

The part in green is to check whether the area which the player clicks is within the maxMove stat for the character. For this version, it is in green just so we can test the gameplay.

This section is to say what happens when the player clicks on an area which is outside the area of the maxMove stat. So, if the player does click outside the area, it will change the isMoving stat to false, the character will not move and reset its path to nothing. Easy tings.

The final part of the character movement script! All it says is, if the isMoving boolean is true, then the nAgent will set the destination and move to the selected position.

A new variable! A float to indicate the total distance.

The only change here is that there is now a restriction on the movement, so they can only move the distance that is provided. As well as, the player can only click on a point that is within the area of movement.

Here is where the float variable is being used. It is being used to indicate how far the distance between the original position and the end position is.

Character Stats Code

This is the code for the stats of the characters. There is not a lot of code needed for this part since it just holds the name of the stats. It also draws the range of the characters on how far they can shoot. This can be changed very easily to showcase the other stat ranges. The stats which the player and AI have are:

  • HP – How much health the characters have
  • Range – The range of the weapon
  • Move – How far the character can move
  • Accuracy – Percentage chance of hitting bullet
  • Mana – Universal, skills cost mana
  • Weapon Damage – How much damage the weapon deals

The only other thing it has is the change in the hit points of the characters, AlterHP. This is specifically for when the player or AI shoots one another and hits them. It is created so it is easier to change the hit point stats.

These stats affect both player and AI.

As can be seen, not a lot of code here

If needed, more stats can be added here, and very easily.

I did make some changes to the stats scripts. I first added the defence stat since we now need it and got rid of the mana stat as we want the player to play however they want. I also added the defence formula into the AlterHP, and it works.

Design a site like this with WordPress.com
Get started