Reader small image

You're reading from  Enhancing Virtual Reality Experiences with Unity 2022

Product typeBook
Published inNov 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781804619537
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Steven Antonio Christian
Steven Antonio Christian
author image
Steven Antonio Christian

Steven Christian is an Augmented Reality Developer, Animator, and Medical Student Student. He's also the Owner of Iltopia Studios where he creates comics and cartoons that explore the Black experience in America. He is Unity Certified 3D Artist and Instructor and his goal is to improve equity in arts and technology through content creation and community-focused education.
Read more about Steven Antonio Christian

Right arrow

Destroying Objects in Virtual Reality

Even though we are not solely focused on making video games in VR, we’re concentrating on creating experiences in general. Having the ability to manipulate destruction and destroy buildings is a valuable asset because, just as much as people enjoy building things, they also like tearing them apart and recreating them into something else. Even if you want to create something that allows you to make destruction less destructive through VR, implementing a destruction system into those experiences can take you very far.

Mastering the nuances of dismantling virtual GOs, particularly in Unity, is an intricate art. Efficiently creating and erasing objects, while ensuring their seamless integration into the experience, paves the way for captivating virtual realities. While the act of destroying objects may seem straightforward—employing a basic method to eliminate the object—it’s the strategic application of this method within...

Creating a grenade

Our first project is creating a grenade, and we will use it as a way of applying force in a variety of different directions so that there is a broad impact in our VR scene. Creating a grenade requires a strategic approach, specifically because it requires you to grab the grenade, arm it, and then throw it. Once the grenade is thrown and armed, it will detonate after a certain amount of time. If you don’t arm the grenade and throw it, it won’t detonate. And if you don’t throw it soon enough, it can detonate in your hand. Being able to create this experience is unique and can be fun because it allows you to implement something very simple and get a nice result.

For this project, we’ll start by creating a grenade mesh with simple objects. Then, we’ll create a C# script that can be used to arm our grenade and apply different settings and properties, such as impact force and other things. We will then create a spawn portal that will...

Making a simple hand cannon

When I was considering what approach to take with projectiles, I reflected on what I enjoyed about my personal experiences with them, which mainly involved video games. One of my favorite games was Mega Man, and what I liked about it was that he utilized the resources in his hands to do a lot of interesting things. It just so happened that one of his hands was a hand cannon.

To be respectful of the idea of guns and their use, which is infrequent in reality, I wanted to approach weapons in a way that felt approachable for everyone. This is something to keep in mind when working on VR experiences since there isn’t a one-size-fits-all solution, but there is a solution for every problem. Projectiles are here to stay, but when creating experiences, some people may not want to use guns all the time, and that’s perfectly fine. Understanding this in the development process is essential because it allows you to find ways to address sensitive topics...

Making a complex hand cannon

This section is going to be somewhat beefy, partly because we will be implementing a lot of different features into this hand cannon. Although it would probably be good to split this up into multiple chapters and focus on the different implementations of HandCannon, we’ll cover all the hand cannon stuff first before revisiting the concepts of projectiles. More importantly, this builds on the foundation we already have, so it’s not necessary to walk through the basics of developing something like this at this point in this book. By the end of this section, you’ll have a solid understanding of how to create projectile sources, which will lay the foundation for when we add our projectiles since it’ll give you a lot of ideas of what projectiles can be used for this cannon.

As mentioned previously, we’re going to cover a lot of different things. We’ll start by making a C# script that allows us to put everything we...

Making projectiles

Making projectiles is not as complicated as creating the actual projectile sources. However, they can be customized if you give them different properties that react differently in the virtual world. The best part about projectiles is their variability and versatility. In this section, we will explore a variety of ways to customize the experience of using our hand cannon.

Projectiles are what make hand cannon fun to use. By creating immersive experiences with sound, impacts, force, and physics, we can make some exciting experiences using a simple projectile. In this section, we will cover how to create a simple projectile, add an impact prefab to indicate that it hit an object, and make complex prefabs to utilize a variety of different properties that we created the framework for in our complex hand cannon. We will start with the basics and then build up to more complex features, leaving it to you to create the variance and variability as you see fit.

To create...

Making projectile variants

As mentioned in the previous section, projectile variants are crucial when we’re trying to add variability to the HandCannon experience. This allows us to add features that are unique to that projectile and remove features that are probably unnecessary. In the context of not having a one-size-fits-all solution, you could create a variety of different projectiles that have gravity effects, force effects, and visual effects that are interesting and appealing. By providing this variability, you allow your users to choose what they enjoy and avoid what they don’t. In many ways, this is all about customization and creating variants that have the same concept but are implemented differently within the virtual world. That’s the way to go.

Making a rapid-fire projectile

We will start by making a projectile variant that utilizes the default projectile that we had but has slightly different properties such as rapid fire. To make a rapid-fire...

Destroying GameObjects with projectiles

The core focus of this section is on destroying GOs, not just using the destroy function within a C# script, but creating a destructive experience and putting that in the hands of the user who navigates the virtual world. It’s not fun if everything is pristine and perfect without any damage or water damage on anything. Nobody wants curated experiences that don’t have a chink in their armor. By allowing users to interact with the virtual world and have consequences for those interactions, whether good or bad, we can tap into the risk-reward feature and element of VR. If there’s something to lose, that means there’s a risk and a reward, and people will risk what they have to lose to go for that reward. It creates an innate challenge that is interesting to see play out when you release your projects and share them with the world.

To destroy GOs when they are hit by projectiles, follow these steps:

  1. Open the...

Adding health to an object

A health system, or hit points as it’s known in the gaming world, is a way to determine how many projectile impacts a virtual object can withstand before it’s destroyed. This is the perfect way to implement our destruction system because we want to be able to set a building’s destruction to something high and a rock’s destruction to something low. Having this variability while also keeping it simple is ideal for a health system within a virtual world, especially since you don’t want to waste too much time on this implementation when you have other things you want to do with the experience.

In this section, we will cover how to add health points to an object and then add damage points to our projectiles. The interplay of these two elements gives us a robust damage and health system that allows us to lay the foundation for how our objects are destroyed in our VR scene.

Adding health points

To add health points to...

Creating a shatter prefab

One of the challenges of creating VR applications is creating realistic effects, such as the destruction of GOs. In this section, we will explore how to create a ShatterParticles prefab in Unity to simulate the destruction of a GO. We will go through the steps involved in creating this effect, including creating a C# script, adding Rigidbodies and colliders, and distributing the particles in a variable area. We will also learn how to make variant ShatterParticles prefabs that can be used in different contexts. By the end of this book, you will have a solid understanding of how to create realistic destruction effects in your VR applications using Unity.

To create a prefab that simulates the shattered destruction of a GO, follow these steps:

  1. Create an empty GO and name it ShatteredParticles.
  2. Create a new C# script and name it ObjectDestruction.
  3. Open the script and apply the following namespace:
    using UnityEngine;
  4. In the public class ObjectDestruction...

Summary

The real game-changer in this powerhouse of a chapter is the destruction and health system we’ve built for our VR objects. Imagine a world where every building or rock can be destroyed with hand cannons, grenades, or projectiles. This comes to life spectacularly through the use of visual effect prefabs from the Asset Store, adding that touch of pizzazz. At this point, you’re equipped with a treasure trove of assets to craft immersive experiences, a process that would have taken years without our shared journey. Use these skills to develop unforgettable VR experiences.

In the next chapter, we’ll focus on the crucial aspect of optimization. Without it, VR experiences can crash devices or run slowly, leading to poor user feedback. For independent developers and small studios, avoiding poor reviews is essential. Always remember that optimization isn’t just a buzzword – it’s a key to building trust with your users and ensuring a smooth...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Enhancing Virtual Reality Experiences with Unity 2022
Published in: Nov 2023Publisher: PacktISBN-13: 9781804619537
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Steven Antonio Christian

Steven Christian is an Augmented Reality Developer, Animator, and Medical Student Student. He's also the Owner of Iltopia Studios where he creates comics and cartoons that explore the Black experience in America. He is Unity Certified 3D Artist and Instructor and his goal is to improve equity in arts and technology through content creation and community-focused education.
Read more about Steven Antonio Christian