0% found this document useful (0 votes)
2 views

Assignment 4 updated

The document outlines the steps to create a VR Motion Sickness App using Unity 2022, including project setup, VR scene creation, player movement implementation, and motion sickness effects. It details the installation of required packages, configuration of mobile build settings, and creation of UI elements for user interaction. Finally, it instructs on building and testing the app on a mobile device.

Uploaded by

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

Assignment 4 updated

The document outlines the steps to create a VR Motion Sickness App using Unity 2022, including project setup, VR scene creation, player movement implementation, and motion sickness effects. It details the installation of required packages, configuration of mobile build settings, and creation of UI elements for user interaction. Finally, it instructs on building and testing the app on a mobile device.

Uploaded by

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

Experiment-4:

VR Motion Sickness App


Step 1: Setting Up the Unity Project
1. Install and Open Unity 2022

1. Download Unity Hub from Unity’s official site.

2. Install Unity 2022 LTS version (recommended: 2022.3.x).

3. Open Unity Hub → Click New Project → Choose 3D Core Template.


4. Set Project Name (e.g., "VR_MotionSickness_App") → Click Create.
2: Project Setup for VR (Install Required Packages)

1. Open Unity Package Manager:


Window → Package Manager
2. Click the + sign → Select "Add package from Git URL".

3. Paste the Google Cardboard XR Plugin URL:

https://github.com/googlevr/cardboard-xr-plugin.git

4. Click Add and wait for the installation to complete.


2. Configure XR Plugin for Mobile VR

1. Edit → Project Settings → XR Plugin Management.


2. Enable Cardboard XR Plugin (for Android/iOS).
3. Adjust Mobile Build Settings

1. File → Build Settings → Select Android.

2. Click Switch Platform.


3. Player Settings → Configure:

o Resolution and Presentation → Landscape Left.

o Graphics API → Remove Vulkan (keep OpenGLES3).

o Minimum API Level → Set to Android 7.0 (API 24).


o Target API Level → Set to Automatic.

4. Enable Developer Mode on your mobile device.

Step 2: Creating the VR Scene


1. Create a Basic VR Environment

1. In Hierarchy → Right-click → 3D Object → Plane (for the ground).


2. Scale it up: (10, 1, 10).
3. Add a Skybox:

o Window → Rendering → Lighting.

o Environment → Skybox Material → Choose a default skybox.


2. Add First-Person Player

1. In Hierarchy → Right-click → Create Empty → Rename it to PlayerBody.


2. Inside PlayerBody → Right-click → 3D Object → Capsule.
3. Rename it to Player and move it slightly above the ground.

4. Attach Main Camera to the Player (drag Main Camera into Player).
5. Add Rigidbody & Character Controller:

o Click PlayerBody → Inspector → Add Component → Rigidbody.

o Click PlayerBody → Add Component → Character Controller.


Step 3: Implementing First-Person
Movement
1. Create Player Movement Script

Create PlayerMovement.cs:

using System.Collections;
using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class PlayerMovement : MonoBehaviour

public float speed = 0f; // Start at 0 (Stopped)

public float acceleration = 0.1f;

private CharacterController controller;

private bool isMoving = false;

public Button startStopButton;

public Button slowButton, mediumButton, fastButton;

public Slider customSpeedSlider;

void Start()

controller = GetComponent<CharacterController>();

// UI Button Listeners

startStopButton.onClick.AddListener(ToggleMovement);

slowButton.onClick.AddListener(() => SetSpeed(3f));

mediumButton.onClick.AddListener(() => SetSpeed(5f));

fastButton.onClick.AddListener(() => SetSpeed(8f));

customSpeedSlider.onValueChanged.AddListener(SetCustomSpeed);

void Update()

if (isMoving)

{
Vector3 move = transform.forward * speed * Time.deltaTime;

controller.Move(move);

speed += acceleration * Time.deltaTime; // Gradual Acceleration

void ToggleMovement()

isMoving = !isMoving;

startStopButton.GetComponentInChildren<Text>().text = isMoving ? "Stop" : "Start";

void SetSpeed(float newSpeed)

speed = newSpeed;

void SetCustomSpeed(float newSpeed)

speed = newSpeed;

3. Attach PlayerMovement.cs to PlayerBody.


Step 4: Creating the Endless Tunnel
System
1. Create a Pipe/Tunnel Prefab

1. Right-click in Hierarchy → 3D Object → Cylinder.

2. Scale it to form a tunnel:

o Scale (X, Y, Z) → (3, 10, 3).


3. Set Position to (0, 0, 10).

4. Rename it TunnelSection.

5. Convert it into a Prefab:

o Drag it into the Project Window → Prefab Folder.

2. Create a Spawner Script

1. Create a new C# Script → Name it TunnelSpawner.cs.

2. Paste the following code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class TunnelSpawner : MonoBehaviour

public Transform tunnelPrefab;

public float spawnDistance = 10f;

public int maxTunnels = 10;


private Queue<Transform> tunnels = new Queue<Transform>();

void Start()

for (int i = 0; i < maxTunnels; i++)

SpawnTunnel(i * spawnDistance);

void Update()

if (transform.position.z >= tunnels.Peek().position.z - spawnDistance)

Transform oldTunnel = tunnels.Dequeue();

oldTunnel.position = new Vector3(0, 0, transform.position.z + spawnDistance);

tunnels.Enqueue(oldTunnel);

void SpawnTunnel(float zPos)

Transform tunnel = Instantiate(tunnelPrefab, new Vector3(0, 0, zPos), Quaternion.identity);

tunnels.Enqueue(tunnel);

}
3. Attach TunnelSpawner.cs to an Empty GameObject (rename it to Spawner).

4. Assign TunnelSection Prefab to the tunnelPrefab field in the Inspector.


Step 5: Implementing Motion Sickness
Effects
1. Create a Motion Sickness Controller

Create MotionSicknessController.cs motion sickness script:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class MotionSicknessController : MonoBehaviour

public Camera playerCamera;

public Toggle tiltToggle, bobbingToggle, fovToggle;

public Slider tiltSlider, bobbingSlider, fovSlider;

private float tiltAmount = 0f;


private float bobbingAmount = 0f;

private float fovVariation = 0f;

private float baseFOV;

void Start()

baseFOV = playerCamera.fieldOfView;

// UI Toggle Listeners

tiltToggle.onValueChanged.AddListener(ToggleTilt);

bobbingToggle.onValueChanged.AddListener(ToggleBobbing);

fovToggle.onValueChanged.AddListener(ToggleFOV);

// UI Slider Listeners

tiltSlider.onValueChanged.AddListener(SetTiltIntensity);

bobbingSlider.onValueChanged.AddListener(SetBobbingIntensity);

fovSlider.onValueChanged.AddListener(SetFOVIntensity);

void Update()

if (tiltToggle.isOn)

float tilt = Mathf.Sin(Time.time * 0.5f) * tiltAmount;

playerCamera.transform.localRotation = Quaternion.Euler(tilt, 0, tilt);

if (bobbingToggle.isOn)

float bobbingOffset = Mathf.Sin(Time.time * 2f) * bobbingAmount;

playerCamera.transform.localPosition = new Vector3(0, bobbingOffset, 0);


}

if (fovToggle.isOn)

playerCamera.fieldOfView = baseFOV + Mathf.Sin(Time.time * 0.5f) * fovVariation;

void ToggleTilt(bool enabled) { tiltAmount = enabled ? 5f : 0f; }

void ToggleBobbing(bool enabled) { bobbingAmount = enabled ? 0.1f : 0f; }

void ToggleFOV(bool enabled) { fovVariation = enabled ? 5f : 0f; }

void SetTiltIntensity(float intensity) { tiltAmount = intensity; }

void SetBobbingIntensity(float intensity) { bobbingAmount = intensity; }

void SetFOVIntensity(float intensity) { fovVariation = intensity; }

}
2. Attach MotionSicknessController.cs to PlayerBody.

Step 6: Adding UI Elements


1. Create UI Panel

1. Right-click Hierarchy → UI → Canvas.


2. Right-click Canvas → UI → Panel (Rename to "ControlPanel").
3. Right-click ControlPanel → UI → Add:

o Button (Rename: StartStopButton)


o Button (Rename: SlowButton)

o Button (Rename: MediumButton)

o Button (Rename: FastButton)

o Slider (Rename: CustomSpeedSlider)

o Toggle (Rename: TiltToggle)

o Toggle (Rename: BobbingToggle)


o Toggle (Rename: FOVToggle)

o Slider (Rename: TiltSlider)

o Slider (Rename: BobbingSlider)

o Slider (Rename: FOVSlider)

2. Assign UI Elements to Scripts

1. Select PlayerMovement.cs and assign:


o StartStopButton

o SlowButton, MediumButton, FastButton

o CustomSpeedSlider

2. Select MotionSicknessController.cs and assign:

o TiltToggle, BobbingToggle, FOVToggle

o TiltSlider, BobbingSlider, FOVSlider


Step 7: Build and Test the App on Mobile
1. Go to Build Settings → Switch to Android.

2. Connect your phone via USB and enable Developer Mode.

3. Click "Build and Run" to install and test the app.

You might also like