August 2, 2021

Bounty Bros Update #4: Physics, Damage, and Pathfinding

2021 08 02 19 37 1.png 2021 08 02 19 37 1.png Micro Thumbnail

The last two months of Bounty Bros. development has brought some major changes, including a totally new physics system and character controller, along with rendering changes to allow for smoother character movement.

Try it Out!

Here's the link for playing the latest demo in fullscreen, and you can also play it in the frame below.

Note: The web demo may not work or perform well on all browsers or platforms yet. We have run into issues specifically with Firefox on different systems and on MacOS. If you run into problems you may want to try running in Chrome. We will try to address these issues in a future release.

Physics & Rendering Updates

The first couple of updates to Bounty Bros. came as the result of a realization: having the player constrained to perfect pixel alignment with the scene was going to make movement look choppy and make gameplay less precise. The solution was to allow things like the player, enemies, and projectiles to move without having to have pixel-perfect alignment, but to have everything else be perfectly aligned. This way, we preserve the retro look and feel, but we add a touch of modern polish that makes the game nicer to play.

This meant we had to do some drastic changes. Our renderer and collision detection system were built on the fact that pixels were always perfectly aligned. As it stood, we couldn't even represent the concept of a non-aligned sprite, but that was going to have to change for us to do what we wanted.

We did a major update to Bevy Retrograde ( formerly Bevy Retro ), our game engine rendering plugin, and made pixel perfect alignment optional, but default. So you could pick and chose which sprites you wanted to be perfectly algined.

We also needed a total replacement for our previous collision detection system. Not only was it clunky and hard to use, but it was wholly unsuitable for collisions not in a perfectly aligned grid. For this we used Heron.

Heron is a nice-to-use wrapper around Rapier with a very Bevy-oriented user-experience. While it didn't directly expose all of the features of Rapier, it made it a lot easier to use. We loved the idea behind Heron and submitted pull requests for all of the features that we needed that weren't provided yet. After some iteration, it had everything we needed and we were able to integrate it with Bevy Retrograde.

We also added our own special feature for Bevy Retrograde that allowed creating some collision shapes automatically from sprites. We put this to use in Bounty Bros. for things like rocks and cactus which now have a collision shape exactly matching the outline of the sprite. No more bumping into the invisible corners of the square collision shapes!

Damage System, & Pathfinding & Game Over

Now that we had a fancy new physics system, we could use it for damaging the player when he touches something dangerous. We chose cacti as the first "enemy". Now, when the player touches a cactus, he will get hurt and bounce off, with the controls being disabled for just a split second.

To go with this newfound ability to take damage, we gave the player a life bar at the top-left of the screen and a game-over screen to show when the player dies. As a bonus, we also added a pause menu that shows when pressing escape, and made the F11 button put the game into full-screen mode.

Next we moved on to pathfinding so that we could make enemies that would follow the player and walk around obstacles in the map. While pathfinding isn't 100% ready yet and it isn't demonsrated in the demo, we made a lot of progress and did get an enemy following the player. The remaining work is to optimize the navigation mesh generation to avoid making pathfinding more compute heavy than necessary.

Upcomming Work

The renderer for Bevy Retrograde is currently 100% custom and fully incompatible with the Bevy's out-of-the-box renderer. I described the reasons we made our own renderer in Writing Bevy Retro's Renderer. One of the big disadvantages, though, of using our own renderer is that it creates a division in the Bevy ecosystem, because plugins that do any sort of rendering will end up specific to either normal Bevy or Bevy Retrograde. It's not easy to work with both, and it means that Bevy Retrograde games can't use things like the existing Bevy Egui plugin, etc.

Another challenge for us has been MacOS support. MacOS has deprecated OpenGL, which may make it more difficult to support MacOS using our current renderer, if MacOS ever decided to completely disable it.

With these things in mind, we are putting effort now into migrating Bevy Retrograde's renderer to work on top of the Bevy rendering abstraction. This will allow Bevy Retrograde to render along-side all of the other Bevy plugins seamlessly. It will also solve the MacOS problem, because Bevy is built on WGPU, which is capable of targeting MacOS using it's native graphics API.

Still, if we were going to use Bevy's renderer, we had a couple of disadvantages to solve: Bevy didn't run on OpenGL ( aka. older computers and Raspberry Pis ) and it required a 3rd party plugin to run on web. In God's perfect timing, though, the WGPU project had already started re-orgainizing the internal structure, including rewriting their graphics backend implementations to be simpler, and finally removing a troublesome C++ dependency on spirv-cross.

This WGPU re-organization was the perfect opportunity for us to get involved and start helping get WGPU running with Bevy on OpenGL and WebGL. In the last couple weeks we have been doing just that. We've already gotten the current Bevy renderer working on OpenGL and we got most of the WGPU examples working on both OpenGL and WebGL in an experimental branch.

Bevy has also been making great progress on the second iteration of the Bevy renderer, and we will be working to get it working on both OpenGL and WebGL. This will hopefully allow Bevy to run on both Raspberry Pi and Web without requring community plugins!

There's still a lot of work to do to get both Bevy's renderer working and to port our Bevy Retrograde renderer to work with Bevy's renderer, but we are excited not only to be making Bevy Retrograde more supportive of the Bevy ecosystem, but also to be helping bring greater portability to all Bevy games.