How I built the “Training with a partner” AR app

Antonio Furioso
5 min readSep 13, 2022

--

Augmented Reality application

Have you ever thought about how could be useful to train with a partner even if you are alone at home or in other places? Or has it ever happened to you to not remember a gym exercise and don’t know how to do it?

Those things happened to me, and for this and other reasons, I decided to build an Augmented Reality application to help people in their daily training.

Some warnings: I build this AR application even to improve my skill with Unity, Vuforia, and C#. I’m telling you that because the application is a demonstration and contains only 8 exercises that a user can follow by himself.

Why and How I got this idea

During an afternoon in March, I was exploring the potential of Augmented Reality, especially the tools that I could use to build something cool and that could make a difference for certain people.

That afternoon, while I was reading different articles, I read about Mixamo.

For people who don’t know Mixamo yet, this is a company that develops and sells web-based services for 3D character animation.

Mixamo is a place full of characters and animations and so, as a gym addict, when I saw the animations’ exercises I immediately thought: “I have to do something with these animations because it could be very useful for other people and me”.

3..2..1… and the challenge begins!!

The process: Pen and Paper

As I always do, I started to take a pen and some paper to write down the idea and how I could realize it.

My first idea was to create two simple scenes. In the first scene, the user had to be able to choose the exercise that he wants to see and after that, there would be a second scene where the user would see the character doing the exercise.

Obviously, the character must be high at least as a person.

So after I had all things written down, I could start to put my hands in the dough.

SPOILER: As you can imagine or understand, if you work on some project, not everything goes as planned. Continue to read to know what I did.

Build the AR app

I started downloading the character and the animations that I needed from Mixamo. After that, I opened Unity and begin to make the first and the second scene.

The first scene (the MainMenu scene) had to contain all the canvas at the beginning. So, I started to put the title, the description, and all buttons to access the animations.

The second scene (the MainScene scene) is where I set Vuforia ground plane function that allows detecting the plane and place where the user should instantiate the object (in my case, it was the character).

Set the animations

I was new to animations World in Unity, so I decided to follow some tutorials on Youtube to understand how they work.

Besides, I made all the setup, and I saw the first problem that I couldn’t solve because of the lack of my skills: moving the selected animation from the button in the first scene to the character placed in the second scene.

For this reason, I had to rethink the whole user experience. I must proceed with a simplification: move the buttons from the MainMenu to the MainScene scene and make the first a simple screen to start the app.

And here is a second problem, I couldn’t set more animations on a single character because it would start to play all of them together.

What did I do?

I give up on that day.

The next day, I was thinking: “override problem”, “override problem” mmm. So, looking online at what I could do to set more animations, I found the answer that was in front of my eyes: the “override” keyword!

Since that, I discovered that I could override the animation by simply setting them as overrides.

Big discovery!! I could continue!

Start to reordering

The first thing I needed to do before going on with the animation was to complete the first step that a user should take. Start the session.

In the MenuScene, I set the canvas with the title, a description, and a single button to move the user to the MainScene by applying a simple script.

using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour { public void MoveToScene(int sceneID) { SceneManager.LoadScene(sceneID);
}
}

Building the MainScene

Okay, here in the MainScene, the game was simple. I already had everything set, character included. I only had to apply the animations to the player from the buttons.

After I made the buttons at the bottom of the screen, I started to implement the idle animation to the character. Setting the idle animation not only allows me to give the player a default position but also to override that animation and set the new one.

To make this happen, I made two scripts.

The first script that I called “AnimationSelection” which I attached to the canvas GameObject, had an array with all the override animations and a method to call each one when the user taps a button.

using System.Collections; 
using System.Collections.Generic;
using UnityEngine;
public class AnimationSelection : MonoBehaviour
{
[SerializeField] private AnimatorOverrideController[] overrideControllers;
[SerializeField] private SetAnimationExercise overrider;
public void Set(int value) { overrider.SetAnimations(overrideControllers[value]);
}
}

The second script: “SetAnimationExercise” has to be attached to the character to make it read which animation to play.

using UnityEngine; 
using UnityEngine.SceneManagement;
public class SetAnimationExercise : MonoBehaviour
{
private Animator animator;
private void Awake()
{
animator = GetComponent<Animator>();
}
public void SetAnimations(AnimatorOverrideController overrideController) {
animator.runtimeAnimatorController = overrideController;
}
}

This way I only had to set up all the links and overrides in the array for everything to work perfectly. And in the end, add to the “OnClick()” function of each button, the “Canvas” GameObject (the one that contained the array), and set the index of the corresponding animation.

Conclusions

How can this project be improved?

This project was for me an exercise to improve my skills, as I explained at the beginning of this article. So there are a lot of things that could be improved. Some of these are a better User Interface, more exercise, a better menu, a tutorial, and some voiceover that explains the exercises.

Do you agree? If you want to improve it, I can give you the backup to do that.

What could be some use cases?

We know, this project, “Training with a partner” is for training lovers.

Whether at home, in an outdoor location, or at the gym this Augmented Reality app can support people as they do exercises to train their bodies and keep fit.

In what other field could it be applied and where?

Contact me

If you liked the project, and how I worked solving some of the problems I encountered and would like to collaborate with me or just get to know me, write me at contact@antoniofurioso.com.

Until next time 😉

P.S. Here you can see how the app works.

Originally published at https://www.antoniofurioso.com on September 13, 2022.

--

--

Antonio Furioso

Antonio Furioso a Product Manager passionate about Augmented Reality & Computer Vision field. Find more information about him on antoniofurioso.com