KEMBAR78
Lab Manual For Unity | PDF | Unity (Game Engine) | 3 D Computer Graphics
0% found this document useful (0 votes)
39 views7 pages

Lab Manual For Unity

This document provides an introduction to Unity, guiding users through the installation process, project setup, and basic asset creation. It covers player movement implementation using Rigidbody and Collider components, as well as creating a camera follow script for smooth tracking of the player character. The document includes detailed procedures and observations for each step, enabling users to build foundational skills in Unity game development.

Uploaded by

reshma.r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views7 pages

Lab Manual For Unity

This document provides an introduction to Unity, guiding users through the installation process, project setup, and basic asset creation. It covers player movement implementation using Rigidbody and Collider components, as well as creating a camera follow script for smooth tracking of the player character. The document includes detailed procedures and observations for each step, enabling users to build foundational skills in Unity game development.

Uploaded by

reshma.r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1: INTRODUCTION TO UNITY AND PROJECT SETUP

Objective:
 Understand what Unity is and its purpose.
 Install Unity and create a new project.
 Get familiar with Unity's interface and core components.
 Learn how to create and import basic assets.

Software Requirements:
 Unity Hub (latest version)
 Unity Editor (LTS version recommended, e.g., 2022.x or 2023.x)
 Visual Studio (for scripting)
 Windows 10/11 or macOS

Theory Overview:
What is Unity?
Unity is a powerful cross-platform game engine used to create 2D, 3D, VR, and AR games and
applications. It supports C# for scripting and offers a visual interface to manage game scenes, objects,
physics, animations, UI, and more.

PROCEDURE:
Step 1: Install Unity via Unity Hub
1. Download and install Unity Hub from https://unity.com/download.
2. Open Unity Hub → Go to the Installs tab → Click Add.
3. Select the latest LTS version and install with:
o Microsoft Visual Studio (optional but recommended)

o WebGL, Android, or other build modules (if needed)

Step 2: Create a New Unity Project


1. Go to Projects → Click New Project.
2. Choose a template (2D, 3D Core, or URP).
3. Name the project: MyFirstUnityProject
4. Select a location and click Create Project.
Step 3: Explore the Unity Interface
Familiarize yourself with these key windows:
 Scene View – where you build your game world
 Game View – shows how the game looks during play
 Hierarchy – lists all objects in the scene
 Project – stores all assets (scripts, models, sounds)
 Inspector – shows properties for selected items
 Console – displays errors and logs
Step 4: Create and Import Simple Assets
Option A: Create Assets
 Right-click in the Hierarchy → 3D Object → Cube or Sphere
 Position and rotate using the Move/Rotate/Scale tools
Option B: Import Assets
 Download a Unity-compatible .fbx, .png, or .wav file
 Drag it into the Assets folder in the Project panel
 Drag and drop into the scene to use it

Observation Table:

Step Description Output

Unity Installed Installed via Unity Hub Unity Editor is working

New Project Created Created MyFirstUnityProject Empty 3D scene opened

Interface Explored Identified all main windows Screenshot of interface

Cube Object Created Created a 3D Cube Cube visible in Scene/Game View

Asset Imported Imported a custom 3D model/image Asset visible in Project window

Conclusion:
In this lab, you installed Unity, created your first project, explored the interface, and imported or
created basic game objects. You are now ready to start building real-time games.
2: BASIC PLAYER MOVEMENT
Objective:
 Create a player character with movement controls (left, right, jump).
 Use Unity’s Rigidbody and Collider components for physics-based movement.
 Handle user input with C# scripting.

Software Requirements:
 Unity Hub + Unity Editor (3D Core template)
 Visual Studio or other C#-enabled IDE
 Basic assets (Cube for player, Plane for ground)

Theory Overview:
Rigidbody – A Unity component that applies physics (gravity, collision) to GameObjects.
Collider – Defines the shape for physical collisions.
Input.GetAxis() – Detects user keyboard input (WASD or arrow keys).
Movement is handled using physics forces, not by directly setting position.

PROCEDURE:
Step 1: Setup Scene
1. Open your Unity project or create a new one.
2. In Hierarchy:
o Right-click → 3D Object → Plane (rename to Ground)

o Right-click → 3D Object → Cube (rename to Player)

3. Scale Ground to (10, 1, 10).


4. Raise Player above the ground (e.g., position = (0, 1, 0))
Step 2: Add Components
1. Select Player → click Add Component:
o Rigidbody (enables gravity & physics)

o Box Collider (already added by default to Cube)

2. Make sure the Ground has a Box Collider.


Step 3: Create the Movement Script
1. In the Project tab, right-click → Create > C# Script → name it PlayerMovement
2. Double-click to edit it in Visual Studio:
using UnityEngine;

public class PlayerMovement : MonoBehaviour


{
public float moveSpeed = 5f;
public float jumpForce = 5f;
private Rigidbody rb;
private bool isGrounded;

void Start()
{
rb = GetComponent<Rigidbody>();
}

void Update()
{
float move = Input.GetAxis("Horizontal");
rb.velocity = new Vector3(move * moveSpeed, rb.velocity.y, 0);

if (Input.GetKeyDown(KeyCode.Space) && isGrounded)


{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}

void OnCollisionEnter(Collision collision)


{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = true;
}
}

void OnCollisionExit(Collision collision)


{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = false;
}
}
}
Step 4: Apply Script and Tags
1. Drag PlayerMovement script onto the Player object.
2. Select Ground → Add Tag: "Ground"

Observation Table:

Step Description Output

Player and Ground Cube (player) and Plane (ground)


Player floats above ground
created placed

Rigidbody added Physics enabled Player falls due to gravity

Left/right movement, jump on


Script added Handles movement/jump
Space

Player only jumps when touching


Ground tagged Jump works only when grounded
ground

Conclusion:
You successfully created a physics-based player character in Unity. By using Rigidbody and Collider
components, you handled movement and jumping with realistic gravity and collision detection.
3: CAMERA FOLLOW
Objective:
 Implement a camera system that follows the player character smoothly.
 Understand how to use scripting to make the camera track player movement in real time.

Software Requirements:
 Unity Editor with 3D Core Template
 Visual Studio or any code editor
 Existing scene with a Player GameObject (from Lab 2)

Theory Overview:
Camera Follow Logic:
To create a third-person or side-scroller view, the camera must automatically follow the player as they
move. This is usually done by updating the camera’s position every frame in relation to the player’s
position.
Smooth movement can be achieved using Vector3.Lerp() or Vector3.SmoothDamp().

PROCEDURE:
Step 1: Setup Existing Scene
1. Open the project and load the scene from Lab 2 (with player and ground).
2. In the Hierarchy, select Main Camera.
Step 2: Create a Camera Follow Script
1. In the Project tab → Right-click → Create > C# Script → name it CameraFollow.
2. Attach this script to the Main Camera.
3. Double-click to open the script and replace with:

using UnityEngine;

public class CameraFollow : MonoBehaviour


{
public Transform target; // Player reference
public Vector3 offset; // Offset from the player
public float smoothSpeed = 0.125f;

void LateUpdate()
{
if (target == null) return;

Vector3 desiredPosition = target.position + offset;


Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;

// Optional: look at the player


// transform.LookAt(target);
}
}
Step 3: Assign Player to Camera
1. Select Main Camera
2. In the Inspector, under CameraFollow:
o Drag the Player GameObject into the Target field.

o Set the Offset (example: (0, 5, -10))

o Set Smooth Speed (e.g., 0.125)

Observation Table:

Step Description Output

Script Created CameraFollow added to Main Camera Script attached

Player Assigned Target set in Inspector Camera knows which object to follow

Offset Applied Adjusted camera distance and height Camera views player from behind

Game Played Camera moves with player Smooth follow effect visible

Conclusion:
You implemented a dynamic camera system that follows the player smoothly. The use of Lerp()
created a natural camera motion, essential for immersive gameplay.

You might also like