Uncategorized
Getting started with your Third Person Game
November 28, 2017 -
Getting started with your Third Person Game
Difficulty: Beginner
Introduction
The indie game development is a trend nowadays. Recently, we can notice some of the top triple-A developers leaving their jobs, where they use to lead huge projects, to start their own game studios. Or even new talents, from best-selling indie games studios, are refusing to move to major publishers, sticking to their origins to focus on expanding and improving their indie games franchises that made them popular. With the indie games market in such evidence, game developers have more and more tools to develop its own games nowadays. The game engines itself, responsible for making the task of game creation faster and simpler, are even more accessible, without the need of major investments. One of them in special, the Unity game engine, with triple-A quality features, offers affordable conditions for small studios, and even a free personal version. This is a perfect fit for the indie market, following its tendency to grow more and more. The Unity creators also provide a great marketplace, the Asset Store, where it is possible to acquire several professional level packages with fair prices. Such assets can be considered one of the best allies of the indie studios, saving a lot of time and money. There are even top quality, completely free packages to consider, that leaves nothing to be desired in comparison to paid alternatives.What we will build
In this tutorial, we will learn how to start creating a 3rd person game, using a free starter kit that we can acquire in the Asset Store. The 3rd Person Controller + Fly Mode asset is one of the most popular in the Asset Store, and was chosen by the editors as a must have asset , an essential one for those who are getting started with Unity and the store itself. When we have completed this tutorial, we will have a fully functional third-person walking simulation, that can walk, jump strafe, aim, and even fly over the environment.Prefer video format?
If you prefer an alternative (and more objective) version of this tutorial in video form, please click here.Getting started
To complete this tutorial, you need to have the latest version of Unity, and at least a personal free account. If you don’t have one yet, please click here to proceed to the Unity website and follow the steps to choose a plan and download the game engine.- When ready, open the Unity IDE, and create a new project.
- On the editor menu, go to GameObject > 3D Object > Plane.
- Select the Plane GameObject, under the Hierarchy.
- On the Inspector tab, scale it to 2, 0.01, 2.
- Ensure the position and rotation values for it are all 0.
- Check the Convex option under the Mesh Collider section.
- Check the Static option on the upper right side.
- Select the Directional Light GameObject, under the Hierarchy.
- Change the Intensity value to 0.3.
Downloading the assets
If you have not yet downloaded the asset package, please click on the banner above to get it:- On the asset page, click to download it and open in Unity . This may redirect you to the Unity Editor.
- Back to the Unity Editor, the Asset Store tab will appear. Scroll down until you find the Import button, and click on it.
- If prompted to confirm that you are importing a complete project, click on Import.
- Click on the None button to deselect all.
- Check the entire Animations folder.
- Check the Animator folder.
- Under Materials, check the Character physic material.
- Inside Scripts > LevelScripts, select the ThirdPersonOrbitCamBasic script.
- Check the entire PlayerScripts folder.
- Scroll down until the ProjectSettings folder, and check the InputManager asset.
- Click on Import.
Configuring the player avatar
Now we can proceed to setup the player avatar. If you have any custom model, you can import it right now and place it into the scene. Note that it has to be a Mecanim humanoid compatible model. For this tutorial, we will simplify and use on of Unity’s standard assets, Ethan.- On the menu, go to Assets > Import Package > Characters.
- On the Import Unity Package window, click on None.
- Scroll down until you find the Ethan.fbx model, and select it.
- Click on Import.
- Under the Assets folder, go to Standard Assets > Characters > ThirdPersonCharacter > Models.
- Drag the Ethan model to the scene.
- Under the Inspector, set the position to 0, 0, 0.
- Open the Tag selection, and choose Player.
- On the Animator, select the Controller parameter and choose CharacterController.
- Click on Add Component > Physics > Capsule Collider.
- Select, for the Material parameter, the Character physic material.
- Set the center of the collider to 0, 0.79, 0.
- Set the radius to 0.26.
- Set the Height to 1.6.
- Click on Add Component > Physics > RigidBody.
- Set the player Mass. We will use 70 for Ethan.
- Under the Constraints section, check the Freeze Rotation options for the X, Y, Z axes.
Setting the player actions
Now it’s time to setup the player actions. The player actions are defined by behaviours, each one implemented in completely independent scripts. All behaviours are controlled by a behaviour manager, that defines who is the active player action. The manager also contains common features for all behaviours. This design opens the possibility to enable or disable player actions even during runtime.- With Ethan selected, click on Add Component > Scripts > Basic Behaviour.
- On the Player Camera parameter of the script, drag the Main Camera.
- Click on Add Component > Scripts > Move Behaviour.
- Click on Add Component > Scripts > Aim Behaviour Basic.
- Click on the Crosshair parameter, and select DropdownArrow (or any other custom texture you want to use).
- On the Aim Pivot Offset parameter, change the Y value to 1.
- Click on Add Component > Scripts > Fly Behaviour.
Setting the 3rd person camera
The last setup we need is to set our camera as a 3rd person point of view, which will orbit around the player and follow him during his movements.- On the Hierarchy, click on the Main Camera.
- Click on Add Component > Scripts > Third Person Orbit Cam Basic script.
- On the Player parameter, drag Ethan GameObject (or any other custom avatar you have chosen).
- Use the mouse to move the camera.
- Press the directional or w,a,s,d keys to move.
- You can control the movement speed using the mouse scroll.
- Hold the left shift while moving to sprint, and press space bar to jump.
- Hold the right mouse button to aim. While aiming, press the middle mouse button to switch shoulders.
- Press key f to toggle the fly mode.