Ball and Ramp Physics Simulation

Brenda Hill
Fall 2022


Overview

For my final project, I chose to create a ball and ramp physics simulation. A ball drops from its initial resting point, onto a ramp, flies off, and then lastly collides with a floor.

Implementation

In order to create this project, I used multiple previous assignments and labs from this semester. To create the ramp, the user can press the space bar on their keyboard and move their mouse to create the desired ramp shape. The mechanics behind the ramp creation is inverse kinematics. The user's mouse position determines the ramp shape. Pressing the space bar again locks the ramp in place and creates a spline curve. The positions of the links in the inverse kinematics computation are used as the control points of the spline curve. Also, a list of points is created along the curve to use as test points for the ball-ramp collisions.
For the movement of the ball, when the d key is pressed to signal a ball drop, the only force that acts on it is gravity. However, when the ball comes within a specified distance of the ramp, a force is calculated and applied to the ball in the direction of the normal of the ramp at the collision point.
When the ball flies off the end of the ramp, it will eventually collide with the floor. To detect that collision, I use a simple check of the height of the ball. When that collision is deteced, a particle effect is triggered to simulate the ball exploding. Also, an X mark is placed in the location of the collision. If desired, the user can toggle the t key and turn on and off a target location, which appears as a green X.