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 🙂

Echelon Bike Monitor

Background

This weekend I set out to connect to my new Echelon Connect stationary exercise bike with an ESP8266 or ESP32 and display the stats on a small OLED. This turned out to be surprisingly easy thanks to the open source nature of things these days. Huge thanks to snowzach’s github where I found the details of how to connect to the bike using a ESP32 board that I didn’t have. But I did and do have a set of ESP32 Devkit V1 boards and a few SSD1306 Oled screens that would do the trick. Below are the details of what I did and the files that are related to it. Hope you enjoy!

Requirements

Main Components

Secondary Components

  • Soldering Iron
  • Hot Glue Gun (If using my basic case)
  • Micro USB Cable (for power)
  • Spare Wire

Setup

Schematic

Below you can see how the ESP32 Should be wired to the Oled screen.

To flash the firmware plug the ESP32 board into your computer and load the provided Arduino Firmware from my Github page in the Arduino editor. You will need to hold the button on the board labeled ‘en’ when the Arduino terminal shows it is trying to connect to the board.

Case

The case is all slip fitting, and to keep it shut put a dab of hot glue in a couple of corners before closing (be sure to flash the firmware before hand as the case will not allow for pressing of the chip enable button). The ESP32 Chip slips into the bottom square which holds it in place. On the top part it is important that the ‘lip’ of the opening is on the pin side of the SSD1306.

Conclusion and Results

This was a really simple setup and went way smoother with the help of SnowZachs research and code. I would like to remind all readers — this is the most basic setup possible to get the data from the bike, and the UI (at the time of this post) can be seen below.

‘Pow’ == Power

‘Res’ == Resistance

‘Cad’ == Cadence