Invading Spaces! – 7/5/12

In todays session, we made a clone of space invaders. With Unity, I always begin with a basic layout I set my level up and this is what I made my level look like.

Once that was done, it was time to start programming basic movements. In programming and making games, the number one thing is organisation. So I made a couple of folders for the things I needed including Scripts, Scenes and Prefabs.

I then started to program the basic movement of my player. This was very similar to pong last week, except rather than making the object move vertical, I made it move horizontally. After this I then put the code in place for the bullet to fire.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerController : MonoBehaviour
{
    private float moveHorizontal;
    private Rigidbody rb;
    public float speed;
    public GameObject bullet;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();   
    }

    // Update is called once per frame
    void Update()
    {
        moveHorizontal = Input.GetAxis("Horizontal");
        rb.velocity = new Vector3(moveHorizontal, 0, 0) * speed * Time.deltaTime;

        if(Input.GetKeyDown(KeyCode.Space))
        {
            Vector3 pos = transform.position + new Vector3(0, 2, 0);
            Instantiate(bullet, pos, Quaternion.identity, null);
        }
    }
}

So whats happening here? Well in the start function, We are telling Unity to grab the rigidbody component from this game object. In update, we are telling unity that if the axis buttons that are matched to horizontal are pressed, then return this value. That value is then used as a velocity which we multiply by speed and Time.deltaTime.

Finally, if we press the space button, then this will instantiate, which means spawn or create, a game object at this objects position + 2 units on the Y axis.

Next, it was time to make the bullets physics happen. The code for this is fairly straight forward and this is what it looks like.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Bullet : MonoBehaviour
{
    private Rigidbody rb;

    public float Speed;

    
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();

    }

    // Update is called once per frame
    void Update()
    {
        rb.velocity += new Vector3(0, 1, 0) * Speed * Time.deltaTime;
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(collision.gameObject.tag == "Block")
        {
            
            Destroy(this.gameObject);
        }

        if(collision.gameObject.tag == "Bounds")
        {
            Destroy(this.gameObject);
        }
    }
}

Similar to the player object, the bullet object also uses a rigidbody so we grab that in start. In Update() we have it so that the velocity constantly adds 1 unit on the Y axis every frame. Finally we have OnCollisionEnter which is a default Unity function. This basically says that if this object collides with that object then this happens. In this instance, the object is destroyed.

Next, I am going to add a score system and opponents to avoid and destroy in the conquest of becoming the best space invader.


After a couple of more hours working on the game, I have modelled an enemy and managed to add some form of physics to them by making them move left to right, right to left and down when they hit a boundary. I also managed to make a working score system.

Firstly, the score system. As my score system relies on a bullet hitting an enemy object, the score wasn’t counting as the object would be destroyed and so, the score system would not know where to get its information from. I quickly remembered PlayerPrefs.

Player Prefs is a tool built in to Unity that is meant for players of your game to be able to save their settings. However, I have used it here in order to save the score whenever the player received one. In terms of enemy movement, I used the same method as the player movement but without the button press. I then added a collider box to my enemy player and had it so if that collider hits the side boundary, the enemy would move down a row.

The issue with this is that the collider could not be destroyed. So if all the blocks for the enemy were destroyed, and you fired a bullet to the same place, the bullet would get stuck in mid space. I solved this problem by writing code so that if the parent object had no children left, then that object would be destroyed.

To finish it off, I made a game over screen and a main menu. itch.io.

Lets Make Dumb Pong! – 30/04/21

In todays programming session, we finally got rounf to creating a game and we done so by going back to basics! We started by making Pong.

Pong is a classic, simple game that features two paddles and a ball. The objective is to get the ball past the opponents paddle to score points. I started by making a new 2D project and using Unity’s built in sprites.

Once my layout was complete, it was time to start coding. I started off by coding the player paddle first, the player paddle had to feature movement by using a button press. This is my code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed;
    private Vector3 movement;

    

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        float moveVertical = Input.GetAxis("Vertical");

        movement = new Vector3(0, moveVertical, 0f);

        movement = movement * speed * Time.deltaTime;

        transform.position += movement;
    }
}

This essentially gets the vertical input axis which is the up and down arrows and converts the values into a float. I then use that float to create a new Vector3 for movement. Finally, I made the movement responsive to speed and real time.

Next, I started to code the ball movement. Once again, this is pretty straight forward. The ball is going to be moving and for that to happen, it needs a physics component. I attached a rigidbody to the ball and then wrote this code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BallManager : MonoBehaviour
{

    public Text playerScore;
    public Text cpuScore;

    private int playerGoal;
    private int cpuGoal;
    private float rand;

    private Rigidbody2D rb;
    private Vector3 spawn;

    // Start is called before the first frame update
    void Start()
    {
        rand = Random.Range(-6f, 6f);
        rb = GetComponent<Rigidbody2D>();

        rb.velocity = new Vector2(rand, rand);

        spawn = new Vector3(0, 0, 0);
    }

    // Update is called once per frame
    void Update()
    {
        playerScore.text = playerGoal.ToString();
        cpuScore.text = cpuGoal.ToString();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "PlayerGoal")
        {
            playerGoal += 1;
            Start();
            transform.position = spawn;
            Debug.Log("Player+1! || Ball Reset!");
        }

        if (collision.gameObject.tag == "CPUGoal")
        {
            cpuGoal += 1;
            Start();
            transform.position = spawn;
            Debug.Log("CPU+1! || Ball Reset!");
        }
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(collision.gameObject.tag == "Player" || collision.gameObject.tag == "CPU")
        {
            rb.velocity = rb.velocity * 0.2f;
        }
    }
}

Basically, this code detects when the ball has hit a goal boundary and resets the position of the ball back to the center. It will then re-run the start function to give the ball a random physics input.

Finally, the CPU pong paddle. This one is not yet complete but it is functional for now, I’m sure there are ways to make it better. Once again, as it is going to be moving, we need some sort of physics input so I used a Rigidbody again. This is the code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CPUController : MonoBehaviour
{
    private Vector3 movement;
    private Rigidbody2D rb;

    public Transform ball;
    public float speed;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();   
    }

    // Update is called once per frame
    void Update()
    {
        
        movement = new Vector3(0, ball.localPosition.y, 0);

        rb.velocity = new Vector3(0, movement.y, 0);
    }
}

The code itself is small and simple. What I’ve done here is made a reference to the balls transform position. I have then referenced this in the Vector3 for movement on the Y axis.

That is pretty much it, the CPU Paddle is still a bit dumb so there is work to be done on that but for now, it’ll do.

When it comes to making games, I would love to learn to make an adventure type game that matches the likes of Super Mario Galaxy. I want to learn how to make the environments and the movement features in the game, including how the gravity works.

When it comes to programming, I don’t find much of it difficult really, its just trying to remember the components and how to code them correctly. Making sure all the references are in the right place.

When it comes to Year 2 and making a game, I want to make a Super Mario Galaxy like game featuring my character Zero, but I would also love to make a karting game. I’ve always been a fan of Mario Kart so to be able to make my own version or variant of this would be amazing.

itch.io

Maths and Programming Revision – 15/04/21

Data Structures

Data Structures are something that we have briefly covered in maths and programming. There are many different Data Structures but some of the most common ones are:

Arrays: An Array is a collection of variables of the same type. They are sequential which means they can be accessed quickly.

Linked List: A linked list a sequential data structure that consists of sequential data that is linked to each other.

Stack: A Stack is a first in last out data structure, like a stack of plates, individually moving the plates from that stack to another will change the order.

Queues: A Queue is a first in first out data structure, like a real world queue for the latest game release, the first into the store, is the first out of the store.

Selection Statements

A selection statement is a fancy term for conditional statements. These statements come in many forms such as if, for and while.

If Statement: If this condition is currently true, run this code.

For Statement: For every time this condition is hit, run this code.

While Statement: While this condition is true, run this code.

Cross Products

Cross Products have a simple but forgetful solution. The solution is to write out both sets of coordinates and then to plant X, Y and Z in the middle of the numbers, then multiply the values together and subtract them to get the new value. A cross product results in a third vector.

Magnitude

Magnitude comes down to Pythagoras Theorem. X² + Y² = Z². Find the SqRt of Z².

Triangular Sprites

To find the area of a triangular sprite, you square the length and height and then divide it by 2. Length² + Height² = Area. Area / 2 = Triangle Area.

Speed

Speed = Distance divided by time. In this instance it would be 750 divided by 3 which equals 250.

Pythagoras Theorem

To work out the distance between the two characters here, we need to use Pythagoras. We would get Player X² and subtract that from Enemy X², and then do the same for Player Y² and Enemy Y². We would then add the two values together and find the square root.

Finding Angles

In order to work this one out, it would probably be best to try and visualise the situation. In this instance, a triangle is the best shape to visualise what is happening here and where triangles are involved we need to use Trigonometry. Trigonometry has 3 calculations which are sin, cos and tan.

Sin, Which can be found by dividing the Opposite Side by the Hypotenuse Side. (Adjacent)
Cos, Which can be found by dividing the Adjacent Side by the Hypotenuse Side. (Opposite)
Tan, Which can be found by dividing the Opposite Side by the Adjacent Side. (Hypotenuse)

In this instance we want to work out the Hypotenuse as that is the angle between the two values. So we would use Tan0 = Height divided by Distance. Then we would use Tan to the power of -1, 0.2. This gives an answer of 11.31.

Programming Revision – 19/03/21

Matrix Multiplication

Matrix Multiplication is the dot product between each number.

1, 2, 3                                                                    2, 4, 6                                                    Pos1, Pos2, Pos3

4, 5, 6                                    x                              3, 6, 9                    =                             Pos4, Pos5, Pos6

7, 8, 9                                                                    4, 8, 12                                                  Pos7, Pos8, Pos9

Pos 1 = 1×2 + 2×4 + 3×6 = 2 + 8 + 18 = 28

Pos 2 = 2×2 + 2×4 + 2×6 = 4 + 8 + 12 = 24

Pos 3 = 3×2 + 3×4 + 3×6 = 6 + 12 + 18 = 36

Pos 4 = 4×3 + 4×6 + 4×9 = 12 + 24 + 36 = 72

Pos 5 = 5×3 + 5×6 + 5×9 = 15 + 30 + 45 = 90

Pos 6 = 6×3 + 6×6 + 6×9 = 18 + 36 + 54 = 108

Pos 7 = 7×4 + 7×8 + 7×12 = 28 + 56 + 84 = 168

Pos 8 = 8×4 + 8×8 + 8×12 = 32 + 64 + 96 = 192

Pos 9 = 9×4 + 9×8+ 9×12 = 36 + 72 + 108 = 226

28, 24, 36

72, 90, 108

168, 192, 226


Dot Products

Dot product is the cosine of the angle between 2 vectors, multiplied by the magnitude of each vector.

Cosine is the ratio of the side adjacent to an angle and the longest side (hypotenuse) in a right angled triangle.

Dot product is calculated by multiplying together the corresponding component from the 2 vectors and adding up the results.

(1,2) . (3,4)

1 x 3 = 3

2 x 4 = 8

3+8 = 11

________________

(-3, 6) . (2,3)

-3 x 2 = -6

6 x 3 = 18

-6 + 18 = 12

________________

(-1.5,4) . (-4, -0.8)

-1.5 x -4 = -6

4 x -0.8 = -3.2

-6 + -3.2 = -9.2

(2,4,6) . (-0.5, 0.5, -0.5)

2 x -0.5 = -1

4 x 0.5 = 2

6 x -0.5 = -3

-1 + 2 + -3 = -2


Cross Products

The result of a cross product is a new vector at 90 degrees.

Cross Products are a series of multiplications with 2 vectors.

(1,2,3,) – (4,5,6)

                                                     X                             Y                             Z

123123
456456

X = 2 x 6 – 3 x 5 = 12 – 15 = -3    Y = 3 x 4 – 1 x 6 = 12 – 6 = 6    Z = 1 x 5 – 2 x 4 = 5 – 8 = -3

(-3, 6, -3)


Averages (Mode, Median, Range, Mean)

Median refers to middle number in arranged order

if there is no middle, then the middle value of the 2 most middle numbers

Mode is the most common occurrence in a set of data

Range is the largest number minus the lowest number

Mean is all the numbers added together and divided by total numbers in sequence.


Remembering Pythag

SOH-CAH-TOA – The angle can be found in the following ways

Sine = Opposite / Hypotenuese

Cosine = Adjacent / Hypotenuese

Tangent = Opposite / Adjacent

Hypotenuse relates to the angle between the opposite and adjacent. The adjacent is the horizontal base of the triangle and the opposite is the vertical height of the triangle.

Sine, Cosine, Tangent

Loops and Arrays – 12/03/21

Loops and Arrays are pieces of code that can help each other out in various ways because of this, this can make code cleaner, less resource intensive, more responsive and in some cases more accurate.

An Array is a collection of variables used for the same purpose. As an example if we were making a 4 player game and were to give each player 3 lives, rather than having numerous ints per player for lives, we would use an array. It is also worth noting that Arrays keep variables in sequential memory rather than random memory, making it quicker and easier for the computer to find. By making the Array public in the script, the Unity editor allows for us to edit the size of the array and the information it holds.

I have used an Array in a Unity name guessing game, this is what that looks like:

A Loop comes in multiple forms but the most common loops are For and While, a For loop is basically saying ‘For each one of these, do this’. A While loop is saying ‘Whilst this is happening, do this’. The While loop could be useful for a racing game maybe, while this button is held down, then acceleration is increased or while health is below 20%, pulse a red aura around the screen.

Inputs and Outputs – 05/03/21

For todays Programming headache, we learned about inputs and outputs. We learned how to make a save and load system and using controls in video games. So to start, we opened up Unity and created a basic scene. For mine I set up a capsule for a player, a platform, a couple of buttons and text objects.

Once this was done, we went to work on the player movement, this is nothing new to me but I have to demonstrate that what I’ve coded is picked up by Unity. My Player Controller is as follows.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour 
{

	private Rigidbody rb;

	public float speed;

	// Use this for initialization
	void Start () 
	{
		rb = GetComponent<Rigidbody>();
	}
	
	// Update is called once per frame
	void Update () 
	{
		float moveHorizontal = Input.GetAxis("Horizontal");
		float moveVertical = Input.GetAxis("Vertical");

		if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
        {
			Debug.Log("You Pressed S // Down Arrow - This means Down");
        }

		if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))
		{
			Debug.Log("You Pressed W // Up Arrow - This means Up");
		}

		if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
		{
			Debug.Log("You Pressed A // Left Arrow - This means Left");
		}

		if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
		{
			Debug.Log("You Pressed D // Right Arrow - This means Right");
		}

		Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

		rb.AddForce(movement * speed);
	}
}

The code is simple. I made a rigidbody variable component and a float named speed. In Start I locate the rigidbody attached to my Player object. Then in Update, as this runs every frame, it constantly checks for updates. I convert the axis to a float value so I can use this in a Vector3 for movement. The horizontal axis is defaulted to A and D and Left and Right Arrows in Unity, and vertical axis is defaulted to W and S and Up and Down arrows.

I made an if statement to detect the button presses which then prints to the Unity Console when those buttons are pressed. Finally to make the player move, we use the AddForce function from the rigidbody, get the Vector3 named movement and multiply it by the speed.

Next it was time to make the save and load buttons work. I made a script named SaveManager and this is how it looks.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System;

public class SaveManager : MonoBehaviour
{
	StreamWriter fileSave;
	StreamReader fileLoad;

	string saveLoc;
	string playerLastPos;

	public Text gameSaved;
	public Transform player;

	float playerPosX;
	float playerPosY;
	float playerPosZ;

	// Use this for initialization
	void Start()
	{
		//This finds current location of file
		saveLoc = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
		saveLoc = Application.dataPath;
		saveLoc += "/save.txt";

		playerLastPos = player.transform.ToString();
	}

	// Update is called once per frame
	void Update()
	{

	}

	public void Save()
	{
		//Writes user input from file and saves to string
		fileSave = new StreamWriter(saveLoc);
		string infoToWrite = "File Saved";

		playerPosX = player.transform.position.x;
		playerPosY = player.transform.position.y;
		playerPosZ = player.transform.position.z;

		fileSave.WriteLine(infoToWrite);
		fileSave.Close();

		gameSaved.text = "Game Saved!";

		Debug.Log("The file was saved in: " + saveLoc);
	}

	public void Load()
	{
		//Read user input from file and saves to string
		fileLoad = new StreamReader(saveLoc);
		string fileInformation = fileLoad.ReadToEnd();

		player.transform.position = new Vector3(playerPosX, playerPosY, playerPosZ);

		
		
		fileLoad.Close();

		gameSaved.text = "Game Loaded!";

		Debug.Log("The file at " + saveLoc + " was loaded! " + fileInformation);
	}
}

In the Start Function, we determine where to save the save file to and what to call the save file.

StreamWriter and StreamReader are the methods we use to save and load data. So we made a couple of functions called Save and Load. Firstly in these functions, I had to declare the read/write functionality. This was done by opening a new StreamWriter and then saving the information I needed to it before closing the StreamWriter. In my example, I had it so that when I clicked the save button, it saved the players position and changed the text to Game Saved. It saves the players position by saving the transform position to float variables.

For the Loading side of things, we declare a new StreamReader and then that loads the information from the file that was saved previously. In my example, this changes the on screen text to Game Loaded and loads the players previously saved position by making the transform equal to a new Vector3 containing the aforementioned transform float variable values.

Finally for the purpose of gameplay, I added a camera controller, this script simply follows the players transform.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour {

	public Transform target;

	// Use this for initialization
	void Start () 
	{
		
	}
	
	// Update is called once per frame
	void Update () 
	{
		transform.LookAt(target);	
	}
}

Coding Conventions – 05/02/21

Coding Conventions, or rules, are a set of guidelines that help you write cleaner, more secure code. These guidelines can include:

  • Safe: It can be used without causing harm.
  • Secure: It can’t be hacked.
  • Reliable: It functions as it should, every time.
  • Testable: It can be tested at the code level.
  • Maintainable: It can be maintained, even as your codebase grows.
  • Portable: It works the same in every environment.

There are four key benefits to using coding conventions and they are:

  • They create a consistent look to the code, so that readers can focus on content, not layout.
  • They enable readers to understand the code more quickly by making assumptions based on previous experience.
  • They facilitate copying, changing, and maintaining the code.
  • They demonstrate C# best practices.

Coding Convention Examples in the Industry

Insomniac Games

Insomniac Games have their coding conventions published online, accessed through WebArchive.

https://web.archive.org/web/20170602083648/http://www.insomniacgames.com/core-coding-standard/

They use this coding standard so that across the board, whether you have been with the company for 20 years or have just started, the code is easy to read and is accessible. This makes the code easier to locate and debug where problems may occur.

Ronimo

Ronimo have their own convention, which is in detail over on this blog by Joost Van Dongen.

https://www.gamasutra.com/blogs/JoostVanDongen/20170711/301454/The_Ronimo_coding_style_guide.php

He states that there is an exception to every rule. However, keep to these rules as much as possible to maintain a constant layout and style for all the code and when writing a language other than C++, write it as close to C++.

Unity

Although Unity is a Game Engine and doesn’t specifically have their own rules for writing code, they do have a recommended way to writing code and how it should be written.

https://unity3d.com/learning-c-sharp-in-unity-for-beginners

In this document, they explain the fundamentals of coding and that writing clean precise code, can result in better performance throughout the games that have been created.

Programming Terms – 29/01/21

In this blog post, I am going to explain some of the programming terms that we may use in several programming languages.

Declaration

A declaration is a fancy term for creating a class, variable or a function. A class is an object and a function is what that object does. If you declare something, you are creating something.

Operator

Operator’s in code are how we use math’s in code. These include various mathematical symbols that may include but not limited to ‘+, -, /, *, =, ==, +=, -=’. An example of using an operator could be if a player collects a this orb, it adds health to the player.

Ratchet & Clank (2002 video game) - Wikiwand
Health += 25

Class

A class is an object in a game. A class could be a player, a weapon, a car, can be pretty much anything.

GTA V: Get in your car - Orcz.com, The Video Games Wiki

Function

A function is a chunk of code that lives inside of a class, it essentially tells the computer what to do when this code is ran. An example of a function could be how the player moves.

9 Insane Tricks Used By Mario 64 Speedrunners - IGN

Encapsulation

Encapsulation refers to how code is bundled within a script along with the functions that operate that data. This could be used for when a player picks up a weapon, the code would need to encapsulated with the player class for it to be operational.

Best wall weapons to use in Black Ops Cold War Zombies | Charlie INTEL

Variable

A variable is something that comes in multiple forms, this could be a string, bool, char, int, float. A variable is declared by the Type of Variable, the name of the variable and the value of the variable. As an example if we have an Int named Health, that value would start at 100.

Fortnite | Health And Shields - GameWith

String

A string is a variable data-type that basically stores a piece of text. In a gaming example, this could be the players name.

The Legend of Zelda: Links Awakening DX

Bool

A bool is a variable data-type that can only have a true or false value. This could be used in a game to see if the player has a certain item or level requirement to open a door.

Mario has > 3 Stars = True

Conditional

A conditional is a type of statement within some code, often perceived as an ‘if-statement’. Basically IF these requirements are met, then this happens.

Image titled Beat the Third Bowser in Super Mario 64 Step 1
If Mario has 80 Stars then run the code for door to open.

Syntax and Semantics – 26/01/21

Syntax and Semantics are parts of programming that mean separate things in relation to one another.

Syntax

Syntax is the structure or the grammar of a programming language. It describes the way to construct a correct sentence. Errors that occur are a violation of programming rulesw within the set language.

Semantics

Semantics relates to the meaning of a programming language. If everything is syntactically correct and there are no errors, it doesn’t necessarily mean you will get the output desired.

Programming and Operators

OperatorUsage
+Addition
Subtraction
*Multiplication
/Division
=Assigns // Equals
==Is Equal To
!=Is Not Equal To

Debug.Log

Use Debug.Log to print informational messages that help you debug your application. For example, you could print a message containing some text used to describe a line in your code or if a condition has been met.

As an example debug.log can be used to verify some things, such as this complicated maths script I made within unity. If the answer is correct, it outputs ‘good maths’ if its incorrect, it says ‘eh?’.

Programming Symbols

There are a variety of programming symbols that we use but the most common ones are

;A semi-colon lets the compiler know you’ve reached the end of a statement. It’s a bit like a full stop, for code.
{ }These are parentheses. They’re used to group sections of code together. When operating with parentheses, every bracket that is open needs to have a closing bracket.
( )These are standard brackets. Commonly used to hold parameters. Similarly used in maths.

Breakpoints

Breakpoints are pieces of code that stop the code from running when it comes to a certain point, this allows the developer to inspect the code and see what has gone wrong and where it has gone wrong.

When a breakpoint is reached, the script goes in to break mode, this allows the developer to do numerous things.

  • inspect and make adjustments to variables.
  • Stop the script from running.
  • Step through code line to line.
  • Move the execution point so as to resume the application, execution from that point.

Without a debugger, this can become far more complicated as you wouldn’t have anything to refer to if there were any errors.

Bug Fixing and Common Errors

Common mistakes that can occur with programming

  • Capitalisation where it matters, if a variable is named score, it simply cannot be Score.
  • Every { must have a } to close it. Same thing applies to any bracket such as [] and ().
  • Statements and lines have a ; at the end of it, this does not apply for if statements unless it is inside of the if.

Code Fixing Challenge

The bool needed to be set to true and the grammar in the if statement was incorrect.
From top to bottom there should be no curly bracket at the end of monobehaviour and no semi colon after the first if statement, the first if statement is also missing a bracket at the end.

Matrix: Revision – 22/01/21

In todays session we done some matrix revision and learned about transpose and inverse.

Addition – add the numbers in the corresponding spaces of each matrix
Subtraction – Subtract the numbers from the corresponding spaces of each matrix
Transpose – Rows from Left to right, become columns top to down.
Inverse – Swap top left and bottom right and make surrounding numbers negative.

We then went and done some further revision by solving some matrix math problems.

Where are certain matrices used in video games?

Multiplication Matrix may be used in video games such as call of duty when a player picks up a gun. The effect this would have is for the gun to have the same orientation as the player when it is being picked up and moved.

Matrix Transpose may be used when you are inspecting a weapon in call of duty, this helps with the weapon rotation.

Matrix Inversion would be when a player has dropped a weapon and the player needs to revert back to its original state.