Posts

Showing posts from October, 2020

Slow Motion Effect - Unity Game Development Tutorial

Image
In this Unity game development tutorial we're going to look at how we can create a slow motion or bullet time effect in our game.  You can either watch the video version below or continue reading for written instructions. We're going to start with the project we created in our Colliding with Obstacles  Tutorial.  We've got a ball and a stack of boxes that all have a Rigidbody component attached so that they react to forces and collisions.  We then have the following simple script attached to the ball that applies a force when the arrow keys are pressed. using UnityEngine; public class BallMovement : MonoBehaviour { public float forceSize; private Vector3 forceDirection; private Rigidbody rigidbody; void Start() { rigidbody = GetComponent< Rigidbody >(); } void Update() { float horizontalInput = Input .GetAxis( "Horizontal" ); float verticalInput = Input .GetAxis( "

Colliding with Obstacles - Unity Game Development Tutorial

Image
In this Unity game development tutorial we're going to look at how we can make objects collide and interact with each other. You can either watch the video version below or continue reading for written instructions. Right, let's get started by creating a new 3D project in Unity Hub. We'll add a Plane for our floor by clicking the plus button in the Hierarchy panel and selecting 3D Object->Plane. We'll set the Transform of the Plane as follows. Next, we'll create a material to change the colour of the floor. To do this we'll click on the plus button on the Project panel and select Material. We'll name this material 'Floor'. We'll then click on the box next to Albedo in the Inspector panel, and choose a green colour.  We can now drag the material on to the Plane to assign it. We're now going to import some free assets to use in our scene. We'll head over to the Asset Store by selecting Window->Asset Store from the main menu. We

Unity Quick Tip - Assigning a Range to a Field

Image
In this Unity quick tip we'll look at how we can set a range for the number fields in our scripts. You can either watch the video version below or continue reading for written instructions. To demonstrate this, we’ll create a new 3D Project. We’ll add a new script to the Main Camera by selecting it in the Hierarchy, clicking the 'Add Component' button in the Inspector, and then searching for the script component. We'll call the new script Range and double click on it in the Project panel to open it in Visual Studio. Let’s add the following public float field to the script. public float speed; If we save the script and switch back to Unity, we can see that the field is visible in the Inspector and we are free to type any value .  If we now switch back to the script we can use the Range attribute to set a minimum and maximum value for the field. [ Range (0, 10)] public float speed; If we save this and switch back to Unity we can see that the free ent

Accelerating a Space Fighter with Forces - Unity Game Development Tutorial

Image
In this Unity game development tutorial we're going to look at how to make a game object accelerate by applying forces to it. If you'd prefer to watch the video version of this tutorial please click  here . Right, let's get started by creating a new 3D project in Unity Hub. The first thing we need is an object to apply forces to. For this, we'll head over to the asset store by selecting Window->Asset Store from the main menu. We'll search for 'SpaceFighter' and download and import this free asset. Now we’ll navigate to the Meshes folder in the Project panel. From here we'll drag the spacefighter_LOD0 into the scene. We'll reset it’s transform by clicking the three dots in the Inspector Panel and then on Reset. Next, we'll position the camera above the space fighter by selecting it in the Hierarchy, and setting its Transform as follows. We'll also set the Clear Flags value to 'Solid Color' and set the background to black so it looks