Bouncing around


The inspiration


As you've seen, the funny little twist in OverGem is this:

overgem_bounce.gif

This bounce/ricochet effect was inspired by anime!

In several Shōnen, such as One Punch Man, a powerful punch is usually accompanied by this ricochet effect to show impact.

ricochet.gif

A game can be created even around only 1 cool mechanic, this was it. When I fully took on the project and re-designed it, I wanted to capture that feeling, so that every punch/slash/hit you throw in the game felt awesome.

From inspiration to implementation


The first thing I had to do was not use Unity's Physics System.

Unity's Physics System does a lot of heavy lifting, but its made to feel 'realistic' whereas 2D platformers don't exactly have 'realistic' physics. I wanted it to feel tight.

Not going to lie, I'm not much of a physics programmer, so I had to do a lot of looking up and following tutorials. I ended up with a system like this:

collision.png

For movement, I would set a target horizontal velocity according to user input + apply a downward velocity for gravity, then manually perform transfrom.Translate on the GameObject.

I then use Physics2D.Raycast (the red lines in the image above) to detect collision, vertically and horizontally, to adjust the target velocity accordingly (0 if collision detected).

After that was sorted, I needed to figure out the bounce. The solution I settled on was having two player states, a normal state and a 'bounce' state. When the player is hit and in the bounce state, I lock velocity, ignoring that player's input and gravity. I apply force in upwards XOR downwards direction, as well as in the direction of being hit. This way, the player being hit will be sent flying and will 'zig zag' upon impact, which looks and feel closer to the 'reference material'.

The callback looks something like this: 

There's a bit more to the above as there is also a 'charging an attack' mechanic, so the HorizontalBounceForce would actually be scaled by how long the attacking player held down the attack button.

The Update function now has a section like this

When colliding with a platform or wall, I inverse the locked velocity. To give it a bit more oomph, every collision while in bounce state triggers some light screenshake and spawns a particle dust effect (not using Unity's Particle System).

I think the overall effect looks pretty nice, and I hope it'll be fun to play.

P.S. I followed Sebastian League's tutorial on Youtube for the platformer physics, its really good.

Leave a comment

Log in with itch.io to leave a comment.