GDD Lab#3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

UNIVERSITY OF MANAGEMENT AND TECHNOLOGY

Lab Manual# 3
First Person Character
movement using keyboard

Course Instructor
Khawaja Ubaid ur Rehman

Department of Computer Science


School of Systems and Technology
UMT Lahore
Objectives
 The purpose of this manual is to learn First Person character movement in Unity 3D. To learn
how to do player movement using keyboard.

Pre-requisite
 Lab 2
1. Add a 3D object Capsule to your scene.

2. Change the Camera preview w.r.t Player. Adjust the camera position in such a
way camera position and player position is same.

3. Move camera position to the top of player using Move tool.


4. Create a folder of scripts.
4a. In scripts folder create a script FPSController and attach this script on Player.

Note: Class name and script name should be same.


6. In your FPSController class add a variable of type CharacterController. See the
screen shot below.

Character controller:
It is used to handle player movement and collision detection.
Serialized Field:
It is used if you don't want to access variable elsewhere, but you want to set value in the
inspector.

7. Make a variable speed to control player speed as shown in screen shot.

8. Make the following variables to store x-axis and y-axis movement values.

9. Type the following line of code in Update function.

Horizontal is pre-defined keyword used to get input along x-axis in Unity’s Input
Manager.
Time.detlaTime: Interval in seconds from the last frame to the current one.
10. Type the following line of code in Update function to store input along z-axis.

Vertical is pre-defined keyword used to get input along z-axis in Unity’s Input
Manager.
11. Type the following line of code in Update function to move your player along
x-axis. By writing this line of code you can move your player in left/right direction
using A,D, left and right arrow keys.
12. Type the following line of code in Update function to move your player along
z-axis. By writing this line of code you can move your player in forward and
backward direction.

Lab Tasks
1. Add a component of Character controller to Player in Unity inspector window
and assign character controller as a reference to that game object.
2. Adjust the camera position in such a way camera should follow player. [Hint:
Make camera as a child of Player]
3. Add fog to your terrain.
4. Add grass to your terrain.
5. Change the sky box material. Download “Sky5x One” asset from Unity asset store
and import it to your scene. Change sky box to night.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy