Ball Game using Accelerometer & Arduino
Project Proposal PDF : Armball Mania Project Proposal
I was recently experimenting with serial communication between 
Arduino and ue4 and suddenly had this urge to make a fun sensor controlled game. Something different and intuitive !
Now, I 
remember that I had the ADXL from my previous project which had become 
one of my favorite sensor ! - and I knew exactly what to do. I know, I
 know. Why am I using an accelerometer ! Using a gyro would've been a 
better idea. And you're right, That's the intuitive part ! 
The Arduino Part
Before
 everything, I needed to test if it even works. So, I created a demo 
project, where I would control the pitch yaw and roll of a flat 
rectangular object with live inputs from the sensor which Will be in the
 users hands. Serial communication was a bit tricky. And I needed
 to open and close the ports dynamically so that I can change it on the 
go. After a bit of tweaking, I got it to work !
To summarize the 
protocol in English, Ue4 would scream to the Arduino through the open 
tunnel and then Arduino would bundle and send back all the data together
 as a response. And of course, I had to unpack the data later. This 
happens over a 1000 time under a second, giving us a latency free 
experience. 
Now,
 before everything. I needed a system in the middle that would filter 
and smooth out the sensor data to give us a butter like experience, thus
 I played around with some algorithms and got that done with. But,
 even with the smoothing - this felt a bit janky and was popping all 
around, here and there. That's because the accelerometer interprets even
 the slightest torque from my hand, thus the noise like output ! So, I
 had to program in a noise reduction system. - that would only allow a 
certain expected range of change around the present base value. And that
 actually solved quite a lot of the problem.
  
Now, I was going for
 a game that could be controlled with hand movements. Thus I needed 
something to attach the hardware with the user's hand, for ease of use. 
Instead of them just holding it.
So, I got a brand new latex glove 
and sowed the hardware on it - in a more sci-if way. And lastly, I made 
sure to make it look cool ! With this sorted out, I programmed
 in a round object, that would simulate realistic physics and bounce 
around like a real life ball. And although, things were just starting 
off at this point - it was possible to balance the ball and keep it in a
 steady position.
This, although simple - was a fun game on it's 
own. We could spawn the ball on command and watch it interact with the 
cube. Simulating, realistic physics ! And. Man, the glove was cool AF. 
Cutting the fingers was a good idea after-all. It made it so much better
 ! At this point, the base system was almost ready. Just needed to 
develop the full fledged game and decorate it !
The game development partSo, From here. It's all software stuff !
Which is a good thing because you'll get some insight on my workflow in game design. Now. Two things I needed to get started was, A ball and a football field. I modeled the field with all it's individual parts and imported it at first in ue4. What I had in mind was a 90s retro game but with a dash of modern aesthetic as the basic accent of the visual and design.
So, I wanted the field markings to glow brightly. Which was a good decision because it made the user more aware of the structure of the field and the goal posts. I added to the field structure and design inside of ue4 and it looked really great ! Now, things were looking kinda dark and not properly visible. So, I worked a lot on the lighting and the backdrop. To give it a soft moody aesthetics ! A little bit of fog, some soft lighting and some glow.
With this done, I experimented with the ball a lot.
I made it out to glow red, tried to put a arrow on it's head and a lot more. But at last settled with a red cricket ball ! I brought it in and with it's texture done, I replaced it with our initial spherical object.
( Now, the goofs were about to come ! How about this, I'm going to give the player an option to pick between a ball - seems reasonable, a toy pony and a torus ) That would certainly help spice things up !
And,
 oh. The ball would emit a red light to make the Player better 
understanding it's location. The light dynamically interacting with the 
floor and bleeding off to volumetric looked so trippy. I
 almost forgot how painfully setting up the camera or was. I tried to 
make it react to the ball movement but it had some serious drawbacks, 
which I better not get into at this moment. But, Making it static was so
 much better, specially when the control for changing it, was with the 
players !
There was a total of 3 camera angles at this point which was custom made by me. And they could choose any one of it !
There
 was a short moment where I experimented with some wall variations 
around the field. So that the ball doesn't fall off. But, later 
discarded the idea since it would've made it a lot easier ! Okay, now let's get back to lighting and the aesthetic part ! I
 made two studio light and brought in into the map ! It would hang above
 the goal post and shed some buttery smooth green light on it. Man, the 
volumetric made it look so cool ! And it was dynamic. Score a goal and it would change its color to red !
Also,
 I needed to destroy the old ball object, spawn a new one and increment 
the current score. Which brings us to the particle effect !
Now, ue4 provides fantastic tools for visual effects. Which helped me a lot to create the particle systems. This
 world spawn when the ball spawns in the middle of the field and when 
the player scores a goal ! A little bit of explosion, some magic. That 
added a lot of impact !
Wait, it's not done yet !
It took me days to get the UI up and running. 
Since I was making everything up from scratch, it took a lot of time and effort. I
 needed to be able to control the sensitivity, noise reduction and the 
ports all from the UI ! So, the main menu and the pause menu was to be 
made. If the port is abandoned, I needed to close it and stop the 
game. The appropriate message should be displayed and the user should 
have the ability to open the port back again manually and that would 
automatically resume the game - all while Making it look good !
After
 the pause menu was made and working, I wanted to make the main menu 
dynamic. I thought of having a modeled human hand floating and reacting 
live to the sensor, so that the user can see their changes to the 
parameters - live on screen.
And of course I had to work on the lights to make it look beautiful. 
  
Guess what's next ?
The sound design. We needed spawn and score sound effects and different background music - all to be custom made !
After
 giving it some final finishing touches. It was in a presentable 
position ! Lastly, I would color grade to tweak the look and feel of the
 game ! And also fixed some bugs.
With everything done, I finally exported and built the game ! Here's the showcase of the whole thing !
Now,
 the whole project which includes the game, the Arduino code and the 
instructions is uploaded in game-jolt. For anyone to try it out. Here's the link : Click here
Here is the full video log of the development journey !
How to use ?Before you get started, there's some basic things you must do to set this up: You would need an accelerometer of course which is an ADXL345 module and you need to connect it with an Arduino. Now for this project you just need to hook up the SCL and the SDA pins from the module with that of the Arduino along with the VCC and ground. That's it after you are pretty much done with the hardware part. The code will handle the rest. So, you need to upload the code which is provided with this project into your Arduino.
Now, on your PC or 
laptop, open the game and you'll be greater with the main menu where you
 can change some parameters. For starters leave the first two as is ( 
the functions are pretty much self explanatory ) but ! You need to look 
up through which port your Arduino is connected to your PC and sent the 
correct port here on the main menu. 
Now, Press the big white burn 
button - that should start everything up and if you have connected 
everything up properly, it should work wonderfully !
So, press the start game button and you're in.
Here are some shortcuts that might be useful for you : Press
 B to change the ball type, you can press the space-bar or the I button 
on your keyboard to spawn in a new ball. And, you can use C to change 
the camera angle ! Lastly use the ESC key or P on your keyboard 
to pause the game and access the pause menu ! Where you can find all of 
these options again !
Now, talking about the game, it's pretty 
self explanatory. Just pass the ball through one of the two goal posts, 
and you've scored !
Here is the video tutorial and instructional video !

 
 
.png)
.png)
.png) 
 .png) 
 .png)
.png)
.png)
.png)


 
Comments
Post a Comment