Thursday, February 23, 2023

Foundation Year Final Project: Production Week 2.

 For Week 2 of production, I had 2 priorities; Start work on the enemy and the enemy movement, and create a gun for the player.  

I decided to work first on the enemy. This was relatively easy to complete. I created a new gameObject with a Rigidbody2D component, a Box Collider 2D component, and I created a script named "e1Movement." 

Here is the spotPlayer that runs on the FixedUpdate function.

private void spotPlayer()
{
float playerDistance = Vector2.Distance(transform.position, _p1Movement.transform.position);
Debug.Log(playerDistance);
// Occurs if the player's calculated distance is greater than the allotted distance.
if (playerDistance > maxDistance)
{
_rigidbody2D.MovePosition(Vector2.MoveTowards(transform.position, _p1Movement.transform.position, enemySpeed * Time.deltaTime));
}
else if (playerDistance < maxDistance)
{
_rigidbody2D.velocity = new Vector2(0, 0);
}
}

As you can see, the function calculates the distance of the player from the enemy, if the gap is big enough, the enemy's Rigidbody2D moves towards the player. Otherwise, the velocity is set to 0.

Next, I focused on the player's shooting mechanic. 


void Update()
{
gunBarrelUpdate();

if (Input.GetButtonDown("Fire1"))
{
BulletCreation();
}
}
void BulletCreation()
{
GameObject projectile = Instantiate(bullet, gunBarrel.position, gunBarrel.rotation);
Rigidbody2D bulletRb = projectile.GetComponent<Rigidbody2D>();
bulletRb.AddForce(gunBarrel.up * bulletImpact, ForceMode2D.Impulse);
}

I will get to the gunBarrelUpdate() function next, but the BulletCreation function creates a bullet projectile, finds the Rigidbody2D component and uses it to add a force to the bullet. 

One problem I had was that the gun location wouldn't update in line with the player's direction.


I had also resized some of the tiles I used from Kenney, which caused scaling issues, so I removed the tilemap while I fixed them.


To fix the gun issue, I created 4 new gun points that point in 4 directions, and then I created a new function that updates the gunPoint variable in code. 

void gunBarrelUpdate()
{
p1Direction = _p1movement.GetPlayerDirection();
if (p1Direction.x == 0 && p1Direction.y == -1) // South.
{
gunBarrel = South.transform;
}
else if (p1Direction.x == 0 && p1Direction.y == 1) // North.
{
gunBarrel = North.transform;
}
else if (p1Direction.x == 1 && p1Direction.y == 0) // East.
{
gunBarrel = East.transform;
}
else if (p1Direction.x == -1 && p1Direction.y == 0) // West.
{
gunBarrel = West.transform;
}
else
{
gunBarrel = originalGunPosition;
}
}


The code grabs the direction variables from the p1Movement script, and uses them to update the gunPoint variable. 

There is still an issue with the shooting, however, in that when the player is still, the bullet is also still. This is something I am still working on. 


For the next week, I will continue to refine the player shooting and add enemy movement.





Thursday, February 16, 2023

Foundation Year Final Project: Production Week 1.

I've been working on a Foundation Year project for the past 4 weeks, and most of it has been for Pre-Production. While I've done a bit of code already for menus, on Tuesday, I started creating code and functionality for my player.

I found a free asset pack on Itch.io for isometric character movements, which I used for the player. 

I followed a tutorial on YouTube to create a script that allowed the player to move in 8 directions.

I did this by creating 2 functions. The first function updates the player's movementDirection variable by grabbing  the player's input. 



The second function uses the MovePosition() function to move the player based on the newly refreshed movementDirection variable. It works by adding the players position with the direction and the movementSpeed variable multiplied by Time.FixedDeltaTime.


Someone on Discord suggested I used Blend Trees for my animation, and the concept would soon come up on the tutorial video that I was following. The difference between the video tutorial and my game was that I was also using animations for SW, SE, NW, and NE. 


I setup the game so that the player's default state is the "Idling" blend tree. Once the player gains speed, it moves to the "Walking" blend tree before moving to the "Idling" tree again once the player stops. 


It didn't work, initially. I tried to update the game in the 15 minutes I had left in the lesson, and I couldn't figure out why the animations were not updating in the game. 

On Wednesday, I found the culprit. 

I had placed the code for updating the games animation in its own function, and I didn't call it.

After calling the function in Update(), the player now not only moves, but the animation changes to face the desired direction whenever the keys are pressed for that direction. 


Next, I worked on the design of the game. I added assets from kenney.nl to create this small island, using the Tile map system. I used the Isometric Landscapes pack to build ground around the player. 


I then used a combo of that pack, the Isometric Buildings and the Isometric City pack to build a much larger environment. 


I had 3 isometric Tilemaps within the grid in the game. 2 of those tile maps have Tilemap Collider 2D components, preventing the player from going into, or moving past the Tilemaps, creating a wall for the world. 


I used Unity's Tile Palette feature (Window - > 2D -> Tile Palette) to fill the game with the appropriate sprites.  

Ground layer.





Ground + Pavement layer.

Ground + Pavement + Buildings layer.



Next week, I will start to create an enemy, by making the object, and adding a AI movement script. 










Thursday, February 9, 2023

An introduction.

Hello!

My name is Sam and I am a student from the United Kingdom. 

I am a game developer focusing on Unity 2D, and Unreal Engine 5. 



As of the time of writing, I am currently taking a foundation year, but I expect to transition to a Computer Science degree in September. 

I am also learning Japanese and Python in my free time, and I've made some progress in those fields. 

I made this blog so I could showcase progress in topics I am interested in, like game/software development.

Thank you.

Sam. 





My personal fashion journey... so far.

Intro.  Hello! Today I'm going to be discussing my fashion journey so far! Recently I've been getting into fashion as a personal h...