4523 words on this page!
In this lesson, we began properly making our Rube Goldberg experiment which is being made in Unity. Originally, I had a really nice idea to have an apartment which a ball would go around, doing things in there that we would usually do to get ready or something. However, when importing assets, you need to create a new material and apply all of the necessary textures which is something which would take way too long, so I eventually abandoned this and thought I'd create something else instead.
I eventually thought of a race idea where I'd use two balls that would be trying to get to a certain area first. I chose to use these eyeballs which are assets that I got from the Unity store. I gave them both ridgidbody and sphere collider components and raised them into the air. Beneath them, I added a cube, made it a bit larger and made it a slope. The balls would then roll forward and hit the start of the dominos that I began to line up. They would roll off opposite sides since there's another slope, and they would wait for the dominos to fall. For the most part, this didn't take too long, however, having to copy, paste, move, and rotate the dominos was a lengthy process which took quite some time, especially since I had to do the other side separately since I don't know if there's an easy way to mirror it. Eventually, I got to the stage you see in this image.
Next, I wanted to make something the balls could drop into and then the dominos would make something happen to begin their next journey. At first, I wanted to do something like a slingshot that would throw the balls to the next part, however, this would be difficult to make work properly, and I had no idea how it would look, so I decided to do something else. Instead, I made it so the balls would fall into these areas and the last domino would fall onto a button which will remove the flooring beneath the ball, allowing it to drop into the next section. Obviously, this required some code, but it wasn't too much.
Of course for now, the scene looks quite dull and you can't tell whats what, but eventually I'm planning on colouring everything, and I'll probably do one colour for each stage of the race.
As you can see here, I have now completed the base part for the second stage. The balls will now fall into their designated areas and the dominos will drop and remove the floor beneath them, sending them falling to their doom, or the next level. The next stage of completing stage 1 is going to be texturing everything so it looks nice. I'm thinking most of the objects are going to be red, except for the domino pieces that I'll get their own material for.
This is the code that I used to hide the part beneath the balls to make them drop. It's relatively simple. We use UnityEngine and open a class called the script, followed by MonoBehaviour. Within this, I made a GameObject variable that I called blueHoleHide, but I have not assigned anything to it yet. I then opened a void that, once it has been triggered by a collision, will set the active state of the selected piece to false, hiding the piece.
To start designing the dominos, I was going to have to get a texture. I'm not sure if I could've somehow exported the domino piece inside of Unity and used that as the baseplate in Substance Painter, so I just recreated the same one in 3DS Max. One unit of measurement in Unity is equal to 1 metre, so I just set the units to that in 3DS Max and started modelling. I did the same measurements, however, I did rotate it by 90° which I would later find out to be an issue.
Here, I applied the Unwrap UVW modifier and quickly mapped it so I would be able to take the model into Substance Painter and get a texture made up.
I next had to make the domino designs that I would want to be displayed on the pieces. For this, I thought it would be easier to quickly make some designs in photoshop, so I could just import the PNG image and use it on the texture. To make the images that I would use, I first made a central line that would separate the top and bottom dots. I then made one circle and duplicated it around. I then made this patterned design since I would be able to easily hide the circles I didn't need, and show certain ones if I did need them. I only made dominos with the same number on the top and bottom since I didn't have many to texture anyway, and it would mean I wouldn't have to make loads of textures.
As you can see here, I'm in Substance Painter, getting one of the dominos textured. I first applied a plastic material that I liked to the model (after baking it of course) and made it a nice, dull white colour. I then imported the PNG images, dragged them onto the domino piece in the 2D map view, and resized them. I then exported the texture maps (base colour, normal etc.) into a folder on my hard drive and then I could bring them into Unity.
Inside Unity, I put the texture map files into designated folders. I then also made the materials and put them into the Materials folder with their correct maps.
Here, I also was forced to import the domino model to Unity since the materials didn't look right on the dominos I already had made, probably because I didn't use the correct dimensions on the correct axis in 3DS Max.
Finally, this is stage 1, and the beginning of stage 2, complete. As you can see, I made the colour of all the models red in stage 1. I also changed the domino texture, but as previously stated, I had to redo every domino piece. It wasn't too hard, I just had to copy the position and rotation data of the already placed ones into the new models.
I did make a slightly different texture for the
For stage 2, I was going to have the balls drop into a box where they would bounce off of these parts that are sticking out. I had the initial ideas ready, so I quickly booted up 3DS Max again to begin modelling the thing that the balls would bounce off of. In the end, this is what I was left with. Don't really know what I exactly wanted it to look like, but this was good enough.
After modelling that, I went back into Unity and began making the box. I was going to colour this stick thing orange since that is the stage colour, so I didn't have to worry about getting the UV map done and bringing it into Substance Painter. I did have to try to create a glass material though that I would be putting on some walls so you can see through. This took a while to get looking right, but I'm happy with how it turned out. I then also dragged the new model I created into the scene and gave it the orange material before placing them in lots of different places. I didn't realise at the time, but they are quite small for the balls, so I either should've made something larger, or added more to allow the balls to bounce around more.
Next, it was time to start planning what I would make happen to the balls after they had fallen all the way down. My favourite idea was to have a cannon that would shoot them out and to the next stage, so I went with that.
Firstly, I grabbed a simple model from the Unity Assets Store and brought it into the scene. I then created some glass slopes to make sure the balls would fall into them, and it was time to start animating it.
Actually, it wasn't time to start animating. I had a few issues and eventually decided to make two cannons, so each ball could get one each. To make this seem a little better, I also removed the glass slope so the balls pretty much had to fall straight in, otherwise they wouldn't be able to get fired. This would later prove to be very annoying though, since they didn't fall the exact same every time, I would have to continuously keep adjusting the sticks to make sure they made it into the cannons.
After, I animated the cannons leaning forward by using Unity's animation. This would happen after a specific amount of time. I wanted to do it so it would play when a ball makes contact with it, but that was too difficult, and I didn't have lots of time to go over it.
This was the code that we made to get the cannons to fire. Originally, I had a cylinder that I animated with the base of the cannon to push the balls out, but they clipped inside the cannon a lot. So, we went for an explosion force, which is also a lot more realistic. We added a rigidbody that I could assign one of the eyeballs to, so only one gets affected. The force of the explosion was set to a float, in case I wanted to use a decimal amount. We then added a transform to mark where the explosion would occur, which was put at an empty part. Finally, we needed the radius that the explosion would impact. Once again using a float, but I just used 1, which worked fine.
We added a manual way to activate it, which was useful for testing, by pressing the space bar. Creating another void called Boom which was the actual explosion.
Here is the cannon fire script variables inside of Unity. As you can see, I assigned the designated eyeball to it, as well as the correct explosive charge. Because there are two cannons, I had to put the script on both, with two different explosive charges. The radius is kept at 1 since it didn't need to affect a very large area. Here, the force is set to 3000, however, I did change these since the balls would get more and less stuck, no-clipping in the cannon. If they were doing it lots, I had to increase the force to get enough power to get them out and go the correct distance I wanted them to go.
The next stage of my Rube Goldberg Machine was going to be somehow getting the balls into some pipes. Again, I quickly got into 3DS Max and made up some basic models that I could use.
I like the straight one a lot, but the curved one isn't quite perfect. I just added some segments, rotated them by a certain amount and moved the parts until they looked roughly right, but they aren't perfect.
Luckily, because the rims were the same, this made it very easy connecting them together since I could just use the snap tool to put vertices together.
As you can see, inside of Unity, the balls fit nicely inside the pipes that I created, so it's going well so far.
Here, I created a large box that is just in front of the cannons. Ideally, I wanted to make a larger gap for they to fly to, but because of how unreliable they were, this was the best I could do. I had to keep adjusting walls, too, since they would occasionally fly out of the top gaps. It's a bit difficult to see in the image due to the low light levels, but I added two holes at the bottom that the balls roll into, which leads into the pipe works.
As you can see, the pipes begin at the bottom of the big green box. They both take the exact same path down, and I angled them inwards at the end to drop the balls onto something else. I also reused the glass material from stage 2 so you can see the balls drop down the pipes.
As previously stated, these were easy to connect since I could use the vertices snap tool within Unity (pressing and holding V).
Finally, it was time to begin making stage 4. Although I ideally wanted there to be more stages that the balls travelled through, I had taken a long time to especially get the cannons completed. So, my time was limited, and I didn't have many more ideas, so I decided that this would be the final stage. The main thing though was that the video had to be over 30 seconds long, which it already was, so that at least wasn't going to be a problem.
To begin the final stage of this Rube Goldberg machine, I wanted it to be a bit like a rollercoaster or train tracks that the ball travelled along. Originally, I wanted the ball to get flung into the air or do a loop-the-loop. However, the model I made for the tracks was only just the size for the ball, which caused a lot of friction, resulting in the ball not gathering a lot of speed. I thought that as long as there was a little gap, it would be alright, but at least I know that it isn't if ever I do something like this again. Or I will find a way to get a slippery surface that the ball can easily glide across.
Other than the ball's speed issue, I was pretty happy with this model. Although there isn't a lot that went into making this, I think somehow it looks like the most detailed thing that I have put into the project. Even though it is just simple box primitives, stretched out into cuboids and shaped in various ways, it still looks like a pretty neat model.
The one you see here is actually split in 3 parts that are made from one part that I duplicated twice. I simply made a cuboid, duplicated it a few times, moved and rotated it to get the main tracks. I then made a smaller cuboid that I used to make it look like the tracks were connected. Furthermore, I don't fully know why I did it this way, since I very easily could've just kept it as one. But it did make the tracks a lot faster to make inside of Unity — and fewer things in the hierarchy. I also used the snap tool in 3DS Max as well to make sure the duplicates line up perfectly with the original part.
I wanted to get rid of the separate primitives within this model, so to do that, I had to create a custom model by attaching each primitive together. To do this, you first have to select everything, right click and convert them to an editable poly.
Next, I selected one of the pieces, right-clicked and then selected Attach. With this piece selected, any separate piece that is clicked on from now on will get attached to it. So, I went around and clicked on every piece until everything was part of the same model. You can then right-click to get out of that selecting mode, and you can then see the model you have created. This allows you to move everything as one model and texture it as one.
The next part was making the tracks that the balls would roll down. In the end, I just settled with a simple, steep slope downwards. This then abruptly ends, and they roll down another slope. I later realise that I probably don't need the other slope quite as long since with the friction they don't travel fast enough to go upwards, but it doesn't matter too much.
I also would need to change the tracks further later to avoid the balls rolling over the edges quite as much, but it's once again quite random whether they stay on or not.
For the final stretch, I knew I wanted the balls (or at least one) to drop into a basketball hoop, since I found this model from day 1 of this project and knew I wanted to use it to finish the video off. However, I had to make something that would lead down to it, so I thought I should probably use the piston spring thing that we were shown a few lessons back.
To make the spring, I first had to make these three models, or at least 2 to get the spring effect, but I want these three to make it look more realistic. It is important to have at least two since one of them will be the base that doesn't move, but is what the spring joint is attached to. The other one is the springy part that will move when collided with. I just have the additional part in between to make it look like the whole thing is connected. On the base part, all I have is rigidbody and collider components. The top part also has both of these, however, it also has a spring joint component. The very few settings you have to set to make this work is to make sure the Connected Body within the spring joint is the base part's rigidbody. In the Axis row, I set the X and Z values to 0, but 1 in the Y, to make sure it only moves along the Y axis. I then also adjusted the Spring and set it to 100 in this case, to make sure it is sitting at the right height and won't fly back up too high.
As you can see here, I have slightly widened the tracks to make it harder for the balls to fall off the sides. I also added two more spring pistons that the balls will jump down into (hopefully) the basket ball hoop before the endless void.
I then went on to add some support walls that would hopefully stop them from just missing the tracks. The ones surrounding the springs is to try to make sure the balls keep a straight trajectory and don't veer off to the side too much.
To finish off the experiment nicely, I wanted to add some particle effects when a ball went into the hoop. I thought it was probably best to not have it happen at a specific time since it would be too difficult to predict when it would happen, and it would constantly be changing. Instead, I did something similar to the end of stage 1 and beginning of stage 2. I made an empty object just under the hoop and script that would be triggered whenever the piece would be collided with.
This script below is what activates the particle. It wants me to define what particle system it is going to be activating, and the rigidbody of that particle system. It also allows me to change the force, which I just set and kept at 50.
This particle system then worked, but to really finalise the look of it, I changed the colour to blue and green to symbolise the eyeball colours. I also had to make sure I unselected the box for Play On Awake*, since otherwise, it just started playing from the start, which defeats the point of the script.
To complete the Rube Goldberg Machine Experiment, I animated the camera to make it move around, following the balls' movements and show as much of what happens as possible. I'm not going to spoil any of what it does here, but as you can see, there are a lot of key frames of position and rotation.
In this project, the main thing that I think went well was starting to get used to Unity and coding within it. Obviously, I couldn't do the code without some help, however, I still applied it and was able to recreate it again if I needed a second piece of code that was slightly different. Moreover, I also finished the project with a video that surpasses the minimum required length of time. I think I have described the steps that I have taken to get to my result in good detail. I started out just getting used to Unity and the physics engine, to bringing in models from 3DS Max, textures from Substance Painter and putting it all together and making it work. In this project, I have only used two models from the Unity assets store, which is something I am also quite happy with. Although everything could've looked better with more going on and models being more detailed, it shows that this is the first time using Unity. Using tools like 3DS Max to create models that I could bring in was me showing that I was capable of that too.
A few things went wrong with this project, one being at the beginning. Originally, I wanted to use an indoor house asset that I would use as the area. However, this didn't start off well since there were so many materials that needed textures applied, and at the time, I didn't know of a quick way of doing it. Now, I would be able to do it, but it's too late, so that was a good idea, but not executed. Also, it got tricky at times when I had to keep making adjustments to the models since the balls would change their path constantly as the physics engine made it so something different would happen after a while. The main issue with that is it could be working one day, but then I come to work on it the next and one ball would miss the cannon and fall into the void. The other ball would clip inside the cannon too much, that made it impossible to fire properly. Annoyingly, it was something I had to deal with since there wasn't an easy fix, but it gave me more experience with these things and gave me ideas on how to improve on them another time. This also connects to the largest issue I had — the cannon shots. For some reason, the balls would fall inside the cannon hole without trouble, but would clip inside the walls inside. When the animation played, they wouldn't move with it, meaning they could clip further inside. When The cannon would go to fire, sometimes it didn't even have enough power to leave it, other times it would go way too far. This is the reason I had to eventually increase the force of the shot by a lot, but have the green box a lot closer to make sure they both ended up in the same place.
Completing something like this again or something with some similar parts, I would start off by testing things more and finding permanent solutions that would work, mostly 100% of the time. In a proper game, you couldn't have balls only occasionally fall into the cannons, since that would probably be deemed as a bug. Therefore, I could've added a platform at the bottom to let them roll into them, but this worked fine too, just not reliable enough for most games. Furthermore, I would also change the whole area and make it look nice. In this, there was just an empty grey void, so I should've added a sky box or other models as scenery to make it less empty. On top of that, I could've designed the stages better. I think having a specific colour for each stage was a good idea, however, they are very basic shapes and don't look too great. I could've added more in-depth textures to spice up what they looked like, as well as using more shapes to make it less blocky. Although it's pleasant and easy getting models from the assets store, I think it would be better to make my own models for everything. Even if they aren't of amazing quality, it feels better to have something that you have made completely by yourself with nothing of someone else's (unless it's code). Since I also have access to 3DS Max, I think it's worth using it while I can and getting more experience in 3D modelling, UV unwrapping and texturing.
Finally, if I were to publish something like this, I would have to change a few things. Firstly, as already stated, I have models from the assets store. I'm not too sure if this is an issue since a lot of things are paid for, but I still think it would make me happier if I had made most, if not everything. So, there shouldn't be any possibility of infringing copyright on something. Another thing that would need changing if I were to publish would be making sure there aren't any bugs and everything works most, if not every, time. Since the balls can fall off track at multiple stages of the machine, I would need to fix this and add some support to these areas to ensure they don't fall — unless it needs to be completely random luck.
In conclusion, I think this project went quite well, especially since we didn't get a lot of time to practice Unity. I think there is certainly room for a lot of improvement, but I'll be a lot quicker making things from now on since I know a lot more about Unity.
Rube Goldberg Machine Video