Bun & Games – Bunny Heaven v1.06

BUNNY HEAVEN

Managed on Github

[Chrome Users: Webplayer support was recently removed from this browser. I am working to get a WebGL version for this project soon.]

[unity src=”935″]

There are two main controls: Movement (clicking or dragging) & Spacebark.

[You NEED Unity Webplayer to run this]

This image shows basic gameplay. Note the 60+ FPS & only 7 draw calls. Only one draw call is to display the bunnies.

This image shows ~500 animated bunnies. Note the 60+ FPS & only 7 draw calls. Only one draw call is to display the bunnies.

Let’s talk about Bunnies

About three weeks ago, I made a Bunny Heaven Dev Blog about a recent game jam project – Bunny Heaven.

It wasn’t much of a game. It had little interactivity. You could move a dog around chasing cute animated bunnies. The project’s merit is in how I misuse Unity’s default particle system to render 1000 adorable animated bunnies in one draw call.

Recently, work is renewing on this project! This blog post is a log of my thought process on how I utilize the particle system.

Bunny PArticles

From the bottom of Unity's Particle System inspector view.

From the bottom of Unity’s Particle System inspector view. (This image is slightly out of date.)

Unity’s default particle system allows for some limited animation options. You are limited to one material and forward playing animation at a constant rate.

This would simply not do. I had a very particular purpose in mind. I wanted to display a great quantity of bunnies to the screen at once. The most effective way to do this was to avoid GPU bottle-necking myself. Particle Systems typically involve very few draw calls as they let a single shader draw all the various particles.

This was the beginning of Bunny Particles.

From there, the bunnies needed to animate and move in different directions. I accomplished this with a technique I’m calling Epoch Locking

Epoch Locking

According to Google, an epoch is

the beginning of a distinctive period in the history of someone or something

In this instance, an epoch is the moment a particle is locked into in order for it to display an appropriate animation.

This is the origin of my term, Epoch Locking.

How to Epoch Lock

  1. Unity’s particle system animates linearly (according to the curve I have set in the image above).
  2. Unity’s particle system allows manual editing of individual particles.
  3. Unity’s manual particle access allows you to change the age of a particle.
  4. A material sprite sheet can contain frames of bunny animation, even different directions.
  5. By checking the direction particles are moving you can access the most appropriate animation to use. You can save the direction an individual particle is moving in a CPU side array.
  6. Finally, you can manually set the age of that particle to the appropriate time interval to display the animation appropriate for it’s current velocity.
    • If the age drops out of that appropriate epoch, you reset it to the beginning of that time period.
    • If the age is too young, you can set it to the beginning of the epoch.

An early mistake I made with my approach was using an incorrect size for the sprite sheet. It is ideal if the sprite sheet is pixel perfect, meaning that the pixels line up with the pixels of the sprite.

Additionally, I recommend about nailing down the formula appropriate for your epoch period calculation.

You’ll need both the min age and the max age for each individual particle based on how many times the animation will cycle and how many frames you will cycle it through. If the starting lifetime of a particle is high, and the particle cycles through the full animation sheet (even though we never let it), the animation will be faster. You will have to do math in order to achieve your preferred animation speed.

Finally, my current code:

BunnyParticleEpochLocking

If you want more rigorous look at how to Epoch Lock, check out Github – Bunny Heaven.

Modified Animation Rates

There is an unmentioned sub-topic within Epoch Locking here. What if we want different bunnies to animate at different rates?

For example, a bunny is quickly running away from the dog. It should animate more quickly than a bunny that is idly hopping along.

To accomplish this we need to adjust the remaining lifetime of particles each frame. We can modify their lifetime based on the magnitude of their velocity. When a particle is moving quickly, it will age more quickly. Faster aging means faster animation.

BunnyParticleAgeAdjustment

Not Quite an Idle Game

Bunny Heaven’s design is moving in the direction of an idle game.

In the most recent development, I added a point counter that will accrue as the player interacts with the game. The game will have no lose state and allow the player to purchase different ways to interact with the game. However, these new modes of play won’t give exponentially greater points, they will just allow the player more ways to have fun.

This portion will change depending on feedback, but the goal is a no-stress environment where you can interact at your leisure.

Closing Words

The most rewarding part of working on this has been handing my phone to people for them to say “This is stupid” and then proceed to play for another 3 minutes after they felt it wasn’t worth their time.

Forrest has expressed interest in publishing an early version of the game on the Google Play Store. The game would most likely be free and shareable.

 

Thank you for reading,

If you have any thoughts or comments, feel free to reach out!

Comments are closed