Zero-G Pinball
The keys to play this game are as follows: A/D for the paddles, Z for jiggling the table, and Space for spawning a new pinball (up to 2).
This project is the second assignment of the Modern Computer Games class at McGill University. This project is a mini-game representing a pinball machine. However, in this assignment, all object motion, collision detection, and collision handling had to be implemented by code without using Unity's colliders or physics. The different required features with their implementation are discussed below.
1. User-Controllable Paddles: Paddles are user controllable via the Unity InputSystem. At rest, the paddles are set at a rotation of -15 degrees. Whenever the "A" and "D" keys are detected, the paddles are set to rotate at 45 degrees. The code for this can be found in the LeftPaddleController.cs and the RightPaddleController.cs scripts.
2. Table Jiggling : The jiggling of the table was implemented also via the Unity InputSystem. Whenever the "Z" key is pressed, a random X value and a random Z value between -2 and 2 is added to the pinball's velocity. The code for this can be found in the JiggleController.cs script.
3. Random Spawning of Cylinders and Prisms : 3 Cylinders and 4 Prisms are spawned randomly every time the game is launched. Before spawning the objects, there is a verification via the CanBeSpawned method to ensure that there is no overlap between object, and that there is enough space for a pinball to pass through. Prisms are also randomly rotated before spawning, while also ensuring that none of the prism edges are parallel with the X-axis. The code for this can be found in the ObjectSpawner.cs script.
4. Pinball on Pinball Table Logic : As the pinball table is presumed to have a slight tilt, a constant acceleration along the Z-axis is added to the pinball. While the table itself is not rotated, the camera is rotated to simulate tilt. As soon as the table reaches the Z-coordinate of the gutter area, the pinball is destroyed. The code for this can be found in the PinballController.cs script
5. Boundary Collisions : Collisions between the pinball(s) and the boundaries are implemented via an Axis-Aligned Bounding Box (AABB) around the boundaries. The code for this can be found in the WallCollisionsCheck method of the PinballController.cs script. Regarding the inclined boundaries, those were implemented via an Oriented Bounding Box (OBB), the code for this can be found in the InclinedBumperCollisionsCheck method of the same script. Collision with those objects result in a bounce with a little energy loss.
6. Cylinder and Prism Collisions : Collisions between the pinball(s) and the cylinders are implemented via a Sphere-Sphere collision. As soon as a collision is detected between a pinball and a cylinder, a noticeable amount of bounce-back velocity is added to the pinball. The code for this can be found in the CylinderCollisionCheck method of the PinballController.cs script. Regarding the prisms collisions, those are implemented via Triangle OBB (with each triangle face of the prism being analyzed). When a collision is detected between a pinball and a prism, the ball is slowed down by a proportional amount compared to the cylinder bounce-back velocity.. The code for this can be found in the PyramidCollisionCheck method of the same script.
7. Paddle Collisions : Collisions between the pinball(s) and the paddles are also implemented via a Triangle OBB method, with each triangle face of the paddle, as it is a pyramid object, being analyzed. If the paddle is in motion, a proportional acceleration is given to the pinball. If the paddle is at rest, a bounce-back with little energy loss is given. The code for this can be found in the PaddleCollisionsCheck method of the PinballController.cs script.
8. Spawning of Pinball : Whenever the "Space" button is pressed, a pinball is spawned randomly on the table, while ensuring that there is no overlap with other objects or pinballs. A maximum of 2 pinballs can be in play simultaneously. The code for this can be found in the ObjectSpawner.cs script.
9. Pinball to Pinball Collisions : Collisions between pinballs are implemented via Sphere-Sphere collision. Whenever two pinball's collide, a bounce-back velocity is added to each pinball, while also ensuring that the collision is only completed once, not twice (due to, technically, the code being present in both pinballs). Only the earlier spawned pinball will handle the collision. The code for this can be found in the PinballCollisionCheck method of the PinballController.cs script.
Leave a comment
Log in with itch.io to leave a comment.