Drone Simulator Update: The Flying Red Cube Takes Off!
I'm just a drone! I only fly away (hopefully)
Hello all.
Welcome and welcome back.
As we approach the end of the year, I’m acutely aware that my attempts to build a drone have been a little more dilettante than I had hoped. Like many programming projects, my little simulator was at risk of joining the mass graveyard of projects I had begun and abandoned. However, I am determined to make this drone simulator work. (If you only want to look at colorful photos of my progress, just scroll farther down).
Starting Over Again
Here we go again. I reconfigured the entire project, deleting the old one and starting fresh. This time, everything moved along much faster. As a refresher, I am building a drone simulator that is meant to feel realistic and, hopefully, can be interactive (eventually).
I was having many issues making it move forward. The initial issue I had repeatedly was that no matter how much I altered the physics of the drone, it kept falling through space. Then, the drone froze and refused to move. These issues were horribly frustrating. Even with ChatGPT's help, I was stuck. Ultimately, I did what most would advise against: I deleted the old project and started fresh. (This is not ideal, as I didn’t figure out the original errors.)
However, I’ve had the most success with this version! I used a cube as the GameObject here; I assigned it the same Rigidbody component (a package allowing interactive physics in your simulator or game).
This was actually a super exciting moment because my drone worked. Granted, I used a cube GameObject. If you’re wondering why I decided on a cube, I have a working theory that the plane model I used in my last simulator had properties that weren’t interacting with my simulator environment well, which is why the drone simulator wasn’t working. I will eventually remove my cube and return to a more realistic plane model later. For now, we have a cube flying around.
Anyway, I wrote a DroneController script (this is exactly what it sounds like) that just controls my drone's movements. The code is written in C#. There is nothing crazy here, just simple code to get everything moving:
The Flying Cube
The exciting part was this:
At first, I struggled with the simulator’s colors, so the yellow square blends awkwardly into the background. The yellow square is my makeshift drone (my cube). I also used a plane object (if you remember planes from geometry) to create a floor. Otherwise, we’re just looking at a blue, blue sky—which doesn’t make much sense if your drone is starting from the ground.
This drone was incredibly responsive; look at these photos of the little guy flying.
You may also notice it’s moved side to side, which is exciting. That means my script is working with my cube, and my cube (drone) is responding.
Starting from Zeroish
All in all, starting from zero here was a great idea. I think there was something wrong with my file hierarchy and structure in my previous iteration of the drone simulator, so it’s looking a lot more promising this time.
Unity’s steep learning curve continues to remind me of how much I have to learn. I tried to adjust the colors for my eyesore simulator, which took a turn. I was unsure of how to return to my original view once I was stuck staring at this screen:
I then figured out (with a bit of help from my friend AI) that I needed to create some materials to set the colors for my different components and reset my view. I created a DroneMaterial for my drone and a GroundMaterial for the floor.
I created a black GroundMaterial, so this floor should be black. The directional light in Unity seems to be interfering with the black GroundMaterial. For now, it’s staying stubbornly brown. The red color for the cube did take.
Conclusions
Anyway, I’m wrapping up with a red drone and still don't fully understand how the directional light works. Next, I’ll attach a camera view to follow the drone’s movement. I also plan to refine the lighting and revisit a realistic drone model. That being said, my flying cube is doing a great job as a stand-in.
And yes, for the naysayers, I know how silly it is to have a floating cube I call a drone. However, if it acts like a drone - that’ll do for now.
Thank you for reading!
Until next time. Bye.