Fireboi Escapes The Lab - Unity C# Exploration
Fireboi Escapes the Lab features a fire alien that needs to escape a flooding lab, using his charged up fireballs to aid him in the process. This project was created for my university coding class, based on the prompt of “Every 10 Seconds”. It serves to demonstrate my skills in gameplay design and C# coding.
Skills gained:
- Complex line renderer using physics equations.
- Reusable, expandable shooting mechanic using state machine.
- High accuracy, cheap jump mechanic using raycast
- Cheap animation using Visual Scripting (Bolt).
Aiming Mechanic
The aiming mechanic was, by far, the most challenging part of this project; it ultimately required me to create my own system, refering to physics equations in order to calculate the necesairy variables used in Unity’s Line Renderer component.
This process went through several iterations before arriving at the most efficient one. Recommended by my professor, I began by exploring raycasting, which was inefficient as rays cannot be curved and would therefore require multuple instances for every step of the curve. For my second attempt, I refered to online documentation of parabola generation using Line Renderes. Unfortunately, these were all limited to 2D Vector2. However, the article inspired me to create my own function using a Line Renderer component.
‘Point i’ variable:
Line Renderer point = (Point i, Position). Where ‘Point i’ is the specific index of the generated point and ‘Position’ is the vector3 location of said point. Based on this Line Renderer function, I needed to generate a curved set of points that would then render the connecting line.
For the ‘Point i’ variable, I created a loop that would generate each index, stopping at the maximum point: TotalTime/time between points (Aka, ‘Step’).
‘Position’ Variable:
The ‘Position’ variable needed to be calculated through physics.
As the only forces acting on the bullets are its velocity and gravity, I knew that these were the only two vector3 variables impacting the position of ‘Point i’ and therefore the only ones to consider.
As change in position(distance) is = Velocity x Time, I first needed to calculate velocity, which is Acceleration x time. As ‘Step’ is how much time between each point, this is the variable I would be using (which I made smaller to draw a higher resolution curve). As my only acceleration is gravity and my time between points is ‘Step’ I knew that I would need to add the following equations to my loop for every point index:
Final outcome of aiming mechanic:
For the script itself, I created a ‘Draw path’ function that contains a loop for each index that updates position & velocity. I also used a variable from my charge state script (explored further on) to make sure the line renderer is pointing in the same direction as the bullet firepoint. The final result is cheap, reusable and accurate.
Raycasting & Visual Scripting Animation:
Fireboi’s movement was made using a character controller and raycasting. Unity’s Rigidbody “IsGrounded” check often causes unavoidable unwanted collisions, while raycasting’s collision system is a cheap alternative that offers more control and is far more reliable.
For Fireboi’s squishing & stretching animation, I used a state machine in Unity’s Bolt (Visual scripting) to control Fireboi’s stretching animation by reducing and increasing Fire Boi’s X & Y scale through a lerp function. This script creates a smooth animation that, unlike a rig animation, can be edited directly in the engine.
Switch Statments & State Machine Charging Mechanic
For the charging mechanic, I used a switch statement in C# between waiting, aiming and shooting. This efficient shooting mechanic is easily reusable and cheap. This was also linked to Fireboi’s visuals, by reusing the “CurrentCharge” float as the perfect time variable to lerp fireboi’s glow & non glow materials.
Rising Water Function
To simulate a flooding lab, I created a boolean variable that would become true when Fireboi leaves the starting trigger box, triggering a lerp function that would raise the water level every 10 seconds.
Conclusion
For the majority of the mentioned coding methods, it was my first time implementing them in my own game. Although incredibly challenging, I’ve vastly improved my skills in C# coding as a result. Not only by knowing more coding methods but also in learning how to approach errors.
The soundtrack used was also made by myself using the App Garageband.