Here's a nifty little game I made in python called Apex Volleyball!
[WARNING LOUD AUDIO - its from JJK]
Untitled.3.mov
Cool trick though: when you hit the volleyball, its path is determined with machine learning. Even cooler, it's trained with a Gaussian output head (a probabilistic "mixture density" model) to introduce some level of "randomness" and stochasticity.
In the real world, even if you hit the ball in the exact same way (at least you think you do) the path it traverses never feels the exact same. I wanted to create an ML model that does this.
I love video games, and I think the stochastic elements of ML models can create a "lifelike nature" in the world of video games.
- Incoming ball - plain old scripted projectile motion, randomized each point
- Contact - when the ball touches your hitbox, the last 8 frames of state
[ball_x, ball_y, ball_vx, ball_vy, player_x, player_y]plus a contact flag are handed to a Trajectory Transformer with a Gaussian output head. It predicts how the ball launches off the hit and because the head is probabilistic, the outcome is sampled and not fixed - Flight - once it's launched, the model predicts the next 9 frames. After that, physics handles the arc. This is because, found through intensive experimentation (me playing the game a bunch), the ML far-future frames are unreliable.
Hopefully, when I have time, I can fix that up and the full trajectory can be ML!
| Key | Action |
|---|---|
A/D |
Move left / right |
W |
Jump (tap again in the air for a higher double jump) |
J |
Hit the ball |
ENTER |
Next point |
ESC |
Quit |
You can only play the ball off your torso - not your head or legs. Land it on the opponent's side to win the point.
You don't need to know any Python to play - just follow these steps.
1. Get the code. Either download it as a ZIP (green Code button above -> Download ZIP, then unzip it), or clone it with git:
git clone https://github.com/preelshh/apexball.git
cd apexball2. Install Python 3.9+ if you don't have it, from python.org. On a Mac you likely already do - check with python3 --version.
3. Install the three libraries the game needs:
pip install -r requirements.txt(On a Mac, use pip3 instead of pip if pip isn't found.)
4. Run it:
python play.py(Again, python3 play.py on a Mac.)
A small game window opens.
Have fun!