top of page

HCI Lab 3: Roll a Ball in our smartphone

  • Photo du rédacteur: quentinaudy
    quentinaudy
  • 20 janv. 2023
  • 2 min de lecture

In the previous laboratory, we learned how to create a Roll a Ball game in Unity. We improved it and had a great result. In this article, I will briefly present you how to convert this game into an Android version, where we can tilt our phone to move the ball.

This article will be really short because it is a simple process, and I didn't have any difficulty doing it.



This article will be really short so I will not separate it into different parts.

The first major step is to convert the project into an Android one. I already installed the SDK for the Tap to Place project, with all the difficulties (you can read it if you want to remember how to do that). In fact, I just had to switch the platform into the build settings, and I was able to run my application directly on my phone after that without any problem.


Now, I had to change the commands in order to use the accelerometer of my phone as an input. So I deleted the previous Player Input, created a new one with a new action.



I also changed the camera position, in order to have a "table game".


In order to be able to control the ball, I had to change a little bit my PlayerController.cs script. Indeed, in the Start() function, I added the possibility to measure the values given by my accelerometer.


In the FixedUpdate() part, I simply read the values of the accelerometer, show them in the canva and create a movement vector according to these values. This will be replacing the previous one in the AddForce function.


And that's it ! Not really complicated in fact, if we just change the input and adapt the scripts, it is easy. I tried it on my phone, and it worked properly.

I just added two buttons easily, one to restart the game and one to close the application. It was easy because I already learned how to do it in my MRTK project (if you forgot, you can read my complete article on it).

So now, here is a video demonstration of this mini project !




Commentaires


bottom of page