Using the 3d camera mode raylib example as a base, I experimented with raylib until I ended up with what is now a simple aim trainer.
The 3d camera mode example came with a camera already defined with a grid and cube already set up to look at. So quite a lot happened to get to the result in the video above. A brief breakdown of what I added:
- Movement of the camera with WASD.
- Basic gravity and a floor, which is faked by turning the gravity off if we're at 0.0 on the y-axis.
- A reticle in the middle of the screen to assist aiming.
-
Collision detection by using
GetMouseRay
with the center of the screen andGetRayCollisionBox
to check if hit the box. - The ability to click the cube which cycles the colour of the cube.
Next I moved onto trying to make it a bit more dynamic. A new cube would spawn within a defined area, with up to 10 cubes being alive at any one time. And now instead of changing colour when you click the cube, it would be destroyed.
An issue I needed to solve was if you lined up more than one cube and clicked them, all the cubes under your reticle would be destroyed. To fix this I needed to get the cube which was the shortest distance from the camera and only destroy that one.
Which leads us to this more gamified version.
- You start with a time bank of 15 seconds to clear as many cubes as you can.
- A cube appears once per second.
- Cubes come in 4 variants with different sizes and colours.
- If you miss-click and don't hit a cube, you are penalised some time.
- If you hit a cube you gain some time back.
- Your highscore is record during a session.