Posts

Showing posts from February, 2021

How to Make the Camera Follow the Player Using Cinemachine - Unity Game Development Tutorial

Image
In this Unity game development tutorial we're going to look at how we can have the camera follow the player so that they’re always centred in the view. You can either watch the video version below or continue reading for written instructions. OK, we'll start with this scene that has a character we can move around.  We created this scene in our post on using the 'Character Controller' , so take a look if you want to know how it was done. At the moment our camera is static, and we are free to move the character completely out of view. We're going to change this so that our camera tracks the character using a feature of Unity called Cinemachine. Cinemachine provides a suite of tools for creating various different camera behaviours without writing any code. Before we can use this feature, we first need to install the package. We'll select Window->Package Manager from the main menu. We'll search for Cinemachine and install this package. Once this is in

Controlling a Character - Unity Game Development Tutorial

Image
In this Unity game development tutorial we're going to look at how we can use the Character Controller component to move a character around a scene and have them collide properly with obstacles. You can either watch the video version below or continue reading for written instructions. Right, we'll start with this scene that has a character we can move and rotate.  We created this scene in our post on ' Gamepad Input ', so take a look if you want to know how it was done. Previously, we've covered the basic movement, but so far we haven't taken into account any obstacles our character may face. Let's add something to collide with by clicking the plus button on the Hierarchy and selecting 3D Object->Cube. We'll change the Transform of the cube to match the following Let's press play to see what happens. Our character passes straight through the wall. This is expected as we haven't told Unity to include the character in it's Physics c

Renaming a Field Without Losing the Value in the Inspector - Unity Quick Tip

Image
In this Unity quick tip we're going to look at how we can rename fields in a script without losing the values we have set in the inspector. You can either watch the video version below or continue reading for written instructions. We're going to start with a simple scene with a single cube. The cube has the following script attached which rotates the cube at a specified speed using UnityEngine; public class Rotate : MonoBehaviour { public float rotationSpeed; void Update() { transform.Rotate( Vector3 .forward, rotationSpeed * Time .deltaTime); } } We’ll set the rotation speed to 90. When we play the game the cube spins around at the speed we specified. Let’s stop the game and go back to the script. Let's say we wanted to rename the 'rotationSpeed' field. We can right click on the field and select rename. We'll rename it to rotationAmount. using UnityEngine; public class Rotate : MonoBehaviour { publi

Don't Lose Your Work - Unity Game Development Tutorial

Image
In this Unity quick tip we're going to look at some common pitfalls that can cause Unity Developers to lose their work and some tips to help avoid them. You can either watch the video version below or continue reading for written instructions. Right, we’re going to demonstrate using the project we created in our ' Collisions ' video. The first thing we're going to look at is something that probably catches out most Unity developers at some point.  We’ll press Play to start our game and then make changes while the game is running. We can change the position of the ball, and move some of the boxes, and then test out our changes. However, as soon as we stop our game, all the changes are reverted. While this is useful to try out throwaway changes while playing the game, we can quite easily lose wanted changes accidentally. One way to help prevent this is to change the UI Play Tint colour to make it more obvious that we're in Play mode. To do this we'll sele