Week 2

Movement Refinement




During this Week of EEP hours, I refined the movement a little bit more. I felt the movement was faster going diagonally than directely up and down, so I modified the code to look like this:

This however, didn't work. This is because this section of code is in the update function, so this if statement is lowering the speed by 0.5 every frame. This makes the player ridiculously fast. To fix this issue I added a new variable called diagonalSpeed and applied it to the equation.

This successfully worked and the player now moves at a constant speed even when moving diagonal. Here is a video demonstrating the new movement.




After making this code I realised I wanted to create a more smooth and slippery type of movement, so the player will slowly speed up and slow down instead of just instantly moving and stopping. To do this I would have to change the way the character moves. Instead of using transform.position, I would use unity's own physics engine to do it for me. Using rigidbody, i can use a function called AddForce which when applied, adds force in a direction. However this will make the character faster and faster without a top speed. To combat this, I can increase the drag value on the characters rigidbody which will make the character speed up slowly and slow down slowly as well as keep a top speed.

Here is the code I made to create this movement.

In this code, the horizontal and vertical floats are converted into a vector2 which can indicate the movement direction and is multiplied by the speed float and multiplied by Time.deltaTime which makes the character move. I have also added the CalculateSpeed method which can calculate how fast the player is moving. This could prove useful later for potential items.

Tile set and Sprites



I also started looking on the Unity asset store for some free assets to use and found these which I will be using:

Martial Hero: https://assetstore.unity.com/packages/2d/characters/martial-hero-170422


Pixel Monster Pack: https://assetstore.unity.com/packages/2d/characters/pixel-monster-pack-75508


I created a tilemap grid using unity's tilemap system and broke down each tile on the tileset I downloaded, into individual images. Then I randomised which tiles the grid places to create a pattern and simply copied and pasted the pattern to create this tilemap. These screenshots show what I did and the result:



Next I imported a player sprite with an idle and run animation. I simply imported the asset using unity's package manager which automatically split the sprites up for me. I then made animation files and animated the animations provided. I also added a monster sprite that didn't come with animations. Everything together looked like this: