top of page

Unity Development Part 1 and 2

  • kw4u19
  • Mar 25, 2021
  • 5 min read

Updated: May 23, 2021

This development work took place during week 5, one week ahead of the scheduled 4 weeks for development in the project pipeline.


We are now the stage of project where we have the design down and are working through creating all of the assets for the actual game, I have begun building the game in unity with some assistance from James.


On Friday the 12th of March, I began building the game in unity, ahead of a scheduled development surgery session with James, to take place on Thursday the 18th of March.


I have never built a game, or anything else for that matter, in unity and my only experience with it is from the lessons we had at the beginning of the first year on this course. So, every step of this process is a learning experience for me. Despite my lack of experience, I thought I would take the lead on this development because I need other people in the team to have some more specific roles that they are mores suited to, and I am determined to learn quickly and work quickly so we have more time as a team to work on the main experience of this game - beauty.


Here is how development began:

I began this process by first setting up a few solid objects which represent the floating islands in the game level we are using for the vertical slice. This involved creating an asset and just placing it anywhere within the game for the time being, adding a box collider so unity knows it should be a solid object, and this object is a placeholder for one of our floating islands. Then I created a "player" object. So I would be able to test the game as I build it, testing and experimenting with the distances between islands and the game composition.


I then took some time to code the movement for the player character. I watched this YouTube tutorial to assist my script writing, and tried to understand the different terms used - https://www.youtube.com/watch?v=ZvF_MYlt944&list=PLfX6C2dxVyLw5kerGvTxB-8xqVINe85gw&index=2


This tutorial allowed me to learn how to write a basic script so that my player object would be able to move left and right, as well as jump. This was a slow process as I am not familiar with any coding language so I think I need to take some time learning more about script writing and the keywords and functions.


Implementing the player movement and jumping allowed me to start experimenting with the game composition and got me to think about how high should the player be able to jump? How far should the distance be between islands so that they are traversable but there is still some challenge? Play-testing and feedback will allow me to find the right answers to this later on in development.


Here is my script for player movement:


I'm pretty sure a script is made of key parts, usually beginning with a start method for what should be checked for first such as access to an animator or audio source.

A float defines numeric values and stores numbers.

A void is used for a function that does not return a value.

A bool takes true or false values.

A vector represents a direction and magnitude.

Public is an access modifier. It can be accessed by any other code in the same assembly or another assembly that references it.


Script Analysis:


The public float for movementSpeed allows me to change the moment speed of the player, and the one for jumpForce for will allow me to change the jump force of the player, in the inspector in unity.


The Rigidbody2D will allow me to add velocity and forces to the player. This is dragged into the rb slot on the player inspector under the script component.


The private float mx stands for movement on the x-axis.


An Update method pattern simulates a collection of independent objects by telling each to process one frame of behaviour at a time.


The update method inside the first private void defines the mx meaning (input along the horizontal axis) and gets the controller to check for when the "Jump" button is pressed and if the the player is touching the ground. It causes a method to take place called Jump().


Update runs once per frame. FixedUpdate can run once, zero, or several times per frame.


Inside the FixedUpdate method we have shown that rb, the Rigidbody2D on the player and its velocity defines the word movement and then above that we have specified what that movement is; a change of position along the x-axis when the velocity is changed.


The void for jump defines the movement for jumping. A change of position when a velocity is applied to the jump force.


The "public transform feet" is for an object that has been created to apply a method that will prevent the player from jumping while in mid-air. And the method "public bool IsGrounded" checks if the player is touching the ground (this means that everything the player is supposed to walk on in unity needs to be tagged as "Ground"). The object feet has a collider that checks for the ground layer within the range of 0.5f. If it can detect it, the player is able to jump. So put simply, if the player is touching the ground, they can jump. If not, they cannot jump.


That concludes the end of this development session. The documentation below summarises my development surgery with James on Thursday the 18th of March.


Part 2


During the development surgery we looked through my script and fixed any problems that had already risen. For example, I didn't know why my player was rotating sometimes when it jumped and James showed me there was an option to stop this from happening. I just had to freeze rotation on the z-axis in the player inspector.


We then proceeded to write another piece of code, for camera movement. For our side-scrolling game I decided that the camera should follow the player, rather than the game be split into a series of scenes that would change once you passed the edge of the screen. James explained the process of the script writing as we went along so I was able to pick up the reasoning of using different words and how I should go about writing them.


Here is my script for camera movement:

Analysis:


There is a public float so the speed of the camera is able to be changed in the inspector. The private vector3 represents a displacement of direction and magnitude in a 3D space. And a public GameObject has been referenced; the player.


The script starts by defining the offset between the players position and the cameras position.


Then there is the method "Follow" which tells the camera when to move from its own position to where the player is.


Then the LateUpdate checks that the camera is always doing this.


LateUpdate is called after all Update functions have been called.



I learnt a lot from this session and feel a lot more confident about using unity. I do think that there is a lot of independent learning I am going to have to do. My aims for the next week are to draw up the full storyboard of the game with Emilia, which will be documented here in this blog, so I have a good idea of what the game should look like in unity. I will then be able to grey box the full game ready for assets to be implemented as they are produced by the rest of the team and I.

Comments


bottom of page