First Unity Game

This weekend I knew I needed to produce something of my own, and like the Echelon Bicycle Monitor I wanted it to be a standalone ‘thing’ — meaning that once the weekend was over I wanted to be ‘done’ with it. I quote done because nothing is ever done, well I guess until you say it is, so forget the quotes this is done :D.

As the title declares, this is a Unity Game, its not anything crazy, but it did force me to use a large set of tools that I haven’t touched in a while. Those tools are Blender, and the Unity Game Engine. This project serves as a warm up to get reacquainted with the tools in preparation for more ambitious projects.

Blender

I started with a tutorial on modelling a low poly car in blender, I just needed a prop to control in Unity, so why not a car? I followed this tutorial, and ended up with:

Low Poly Car Model

As with anything I am bound to explore more than necessary and I rather enjoyed modeling things in Blender, I desire to get more proficient with materials and shaders though. Shaders were outside of the scope of the goal for the weekend so I moved on with the bare minimum, though I did model more than the car (couldn’t help myself).

Construction Scene Models

Unity Engine

With the low poly car created it was time to start figuring out the control mechanisms in Unity using the Oculus Quest 2 headset. For this I followed this tutorial for the physics of the car controller. For the input though I had to refer to the Unity API for XR Controllers, which isn’t nearly as easy as the old ‘Input’ object I was used to for mouse and key board, but was doable. Ill only explain the input here as more than that would just be reiterating what is in the linked tutorials.

Unity Controller Code

First you have to get the controller, to do this I used the following code:

private void GetRightHand()
    {
        var rightHandDevices = new List<UnityEngine.XR.InputDevice>();
        UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand, rightHandDevices);
        if (rightHandDevices.Count < 1) return;
        device = rightHandDevices[0];
    }

I call this once on ‘Start’ and in a check in ‘FixedUpdate’, the check is to ensure that if we don’t get the controller on game start we get it when it does finally connect.

Once we have the controller we need to get the trigger value, this code handles that:

// Get Accelerator Input
        device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.trigger, out VerticalInput);

Left right control will be done with the joystick on the right hand with this code:

// Get Left Right Input
        device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.primary2DAxis, out joyStickValue);
        HorizontalInput = joyStickValue.x;

Finally, we need to get one button to handle resetting the cars position

device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.primaryButton, out bool reset);
        resetCarPosition = reset;

Unity Scene Setup

To get started with Unity XR setup I followed this tutorial. Once setup it is just moving assets around and getting a game scene setup which for me looks like this:

Low Poly Weekend Car Game Scene View

In the above photo you can see this black box with a car in it and a white track. On the plane infront of the user you can see the goal of the game and when you complete the challenge you are notified with ‘You Won’ on that same screen.

Conclusion

I am pretty sure this meets the criterion for a ‘game’ though it isn’t the most polished thing. I really enjoyed this process and though the number of options available when building games can feel overwhelming going into this process with a clear goal and limited expectations proved to make this a satisfying experience. The files for you to play this locally on your unity instance are below. Thank you for reading 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.