In recent years, virtual reality has become one of the hottest topics around. Though it has been attempted several times in the past, it was often written off as a gimmick before being able to truly take hold. However, this time virtual reality is here to say – so what does that mean for everyone?
With new technology comes new ways to create games. Virtual reality offers a whole new way to immerse players into worlds, provide interactive experiences, and just all-around present stories in a new and different light. Though VR still has some limitations to work out, each virtual reality experience is truly unique when it comes to games – and it’s only getting better.
Thus, whether you’re a beginner or veteran game developer, you might have had your eye on jumping into this fast-growing industry. But… how does one actually code a VR game? In this post, we will help you both understand virtual reality, how it works, and how you can develop exciting games with this exciting, cutting edge technology. Let’s jump into it, and learn just how to code a VR game!
What is Virtual Reality?
Virtual reality (VR) is the simulation of 3D spaces that you can experience through a headset. You can look around and with some headsets – move. With your entire vision being controlled by the headset, along with the ability to move and look around – VR is a very sought out technology.
In some more advanced headsets, you can use controllers which act as your hands. You can pickup objects, throw them and interact with the world around you. Virtual reality is a technology that can be found on PC, mobile and consoles with a wide range of different headsets.
As the years go on, the headsets are getting cheaper and the catalogue of games is getting larger and larger. At the start of the year, Valve released Half-Life: Alyx. One of the first AAA VR game and a major turning point for the industry.
Types of Virtual Reality
When it comes to VR, there are generally two different types of headsets and experiences. Stationary and room-scale experiences.
The most basic form of VR which generally has the cheapest headsets. You can look around in VR, but can’t move your head. These headsets sometimes have a small controller with basic functionality. Having a seated experience is the most accessible type of VR.
Here are some headsets that give you a stationary experience:
- Oculus Go
- Google Cardboard
- Samsung Gear VR
When it comes to having the most immersive experience, room-scale VR is what you want. This form of VR allows you to not only look around, but move around too. These headsets normally also have motion tracked controllers so you can interact with the world.
Here are some headsets that give you a room-scale experience:
- Oculus Rift
- Oculus Quest
- HTC Vive
- Valve Index
- PlayStation VR
Which Game Engine Should I Choose?
When it comes down to creating a VR game, what you need to do is choose a game engine. What’s a game engine? A game engine is software that allows you to create video games. Instead of coding everything from scratch, you only need to code the gameplay aspects. The engine handles rendering, objects, data management and many more things.
When it comes down to virtual reality development – there are two game engines our there which do it great.
Being the most popular game engine, Unity allows you to create pretty much any kind of game. It has universal VR support, which means you can make your game once and can play it on pretty much any VR device. Unity’s VR tools are extensive and require minimal coding.
- Universal VR framework
- Very versatile
- Large amount of platforms to build to
- Less AAA presence than Unreal Engine
- Less graphical fidelity than Unreal Engine
The Unreal Engine has a focus on 3D graphics. So if you want the best visual fidelity in your VR game, then Unreal may be the way to go.
- Graphically, one of the best game engines out there
- Visual scripting (no coding required)
- Less versatile than Unity
Best Practices for VR Development
When developing a virtual reality game, you need to be cautious about how you develop your game. Motion sickness is something that can easily occur in VR. Some people are fine with it, while others are very sensitive to it. There are a number of things you need to keep in mind in order to reduce the chance of motion sickness.
- Only the player can move themselves around.
- If you do want to move the player around (out of their control), either block out their peripheral vision or place the player in a cockpit (stationary context).
- Make sure that the frames per second (FPS) are greater than 60. Low FPS can be a large factor in motion sickness.
- When transitioning scenes or areas, you’ll want to fade the screen out then back in.
- Player movement can be done with smooth movement or teleportation.
- Smooth movement is like any other game. You can press a button or move a joystick to directly move your player around.
- Teleportation is where you can aim your controller point to a location to teleport to. When teleporting, you want to make sure the screen fades out/in to hide the direct change in position.
If you’re wanting to get into VR game development, you should start with the Unity or Unreal game engines.
- Unity Virtual Reality Mini-Degree
- VR Game Development 101 – Platform Setup (Free Course)
- Unity VR Documentation
- Unity XR Interaction Toolkit
- Unreal Game Development Mini-Degree
- Unreal Engine 101 – 3D Game Creation (Free Course)
- Unreal Engine VR Documentation
Here at Zenva, we’ve created a couple of VR games.
Congratulations if you’ve reached this point! While we’ve only just touched the surface here, you should now have a better understanding of how to get started coding your own VR game.
There is, of course, a lot to consider when developing for VR – least of all which headset to target and what sort of game you even want to create. Remember, though, that even if new, VR offers tons of freedom to create novel games never seen before. Virtual reality is truely a new frontier of game development, so even if you don’t stick with it long term, gaining the skills for virtual reality can only be a net positive!