For this assignment I decided to recreate a stacking game, where a cube is dropped from the top and you have to time the drop in order to continuously stack the cube. It is an endless game, so the only way to lose is if the boxes fall over and you didn’t stack it successfully. Unfortunately, I couldn’t find a fake game ad of this particular game, but I found an example of the game (it’s called Tower Stack on Facebook):
DEVELOPMENT PROCESS
I first referenced a YouTube video to set up the scene. While this assignment is to use primitive objects like spheres and cubes, I still wanted to make it look more like a game. I watched this YouTube video, but instead of using cakes I used cubes.
I didn’t follow the YouTube video because it wasn’t what I was looking for. So I used ChatGPT to create the code. So I typed in this prompt for ChatGPT:
Can you write a unity C# script where a box is dropped at the top of the screen and has to stack on a box that is at the bottom of the screen. The box at the top of the screen is moving left and right automatically. The box is dropped by pressing space. If the box dropped from the top is stacked on the box at the bottom, then another box at the top appears and does repeats the process.
I’m not sure if it is specific enough, but even though I didn’t specify that it was a stacking game, it automatically figured it out. Here is the script that it provided:
In order for this to work, I had to create empty GameObject first and attach the script to it. Then I had to attach a “prefab” cube to the variable “Box Prefab” in the script. The second step was to attach a bottom box to the variable “Bottom Box” but ChatGPT said to have an empty GameObject, whereas I have a platform for the box to land so I decided to attach the platform instead. After doing all these steps, the moment of truth was to test run the game.
There are quite a few issues: one, the cube drops automatically and another cube does not respawn. Two, you can see the position changing, but nothing is moving. So I asked to include these things in a modified script:
I want the cube at the top to move left and right automatically and only drop when the player hits space, rather than having the player control it manually. Also, a new cube does not spawn after dropping, so can you please add that script as well.
With the new script, the box still drops down by itself. So I decided to uncheck “use gravity” under rigid body, which made the box stay up but when I press space it doesn’t drop. Furthermore, you can see that clones are being created but you can’t tell if they are because the first box is still at the top of the screen. Also, the box still doesn’t move left and right automatically.
I checked the console and there was an error saying “there is no ‘Rigidbody2D’ attached to the ‘Base cube(Clone)’ game object, but a script is trying to access it.” Initially, I tried to attach this, but it says it conflicts with the existing BoxCollider component. After asking ChatGPT what the issue is, I realized that ChatGPT was creating a 2D environment while I was working in 3D, so there were conflicting variables and components.
Another issue was that the newly spawned cube has no Rigidbody, so the function to drop a box was modified. Here is another test run:
The spawning worked, but not the way I was expecting. The top box does not drop (and it still doesn’t move left to right). Then the boxes spawn so much smaller that the original one and they appear from below the platform.
I realized that the reason why the box keeps spawning below the platform is because the GameObject where the box will spawn is positioned before the platform. So I moved the GameObject to the same exact position as the Prefab Cube and scaled it to be the same size as well.
There’s still an issue with the size and stacking of the cubes. For some reason, the cubes would spawn behind the previous one or in front, which will eventually stack, but it doesn’t stack one by one. Moreover, scaling the GameObject was not correct, and I realized that I should’ve scaled the Base Cube asset, so I did that and now the sizes match.
I also decided to change the camera position to see the stacking from another view. While this isn’t exactly what I was going for, this is the final iteration of my fake game:
And this is the final iteration of the code:
CHALLENGES AND ACHIEVEMENTS
The most difficult challenge was definitely getting the cube to appear at the top all the time and move left and right. Even though I asked ChatGPT to make the cube move automatically, for some reason it never did that. And I think since gravity is enabled all the time, the cube just automatically falls down. Finally, the stacking didn’t work out the way I wanted it to, so the final iteration is not what I initially intended.
What I found to be an achievement is getting the cube to spawn and sizing it to be the same as the initial cube. Furthermore, it did stack, but just not the way I wanted it to, but it is close a step closer to the final outcome. Finally, I learned how to use AI tools to help me develop code and create a game.
ai tools used