Bouncing around
The inspiration
As you've seen, the funny little twist in OverGem is this:
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.
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:
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.
OverGem
One-Hit Brawler
Status | In development |
Author | Hung Hoang |
Genre | Fighting |
Tags | 2D, Local multiplayer, party-game, Pixel Art |
More posts
- Unity - a statementSep 04, 2021
- Well, it has character(s), part 3Aug 20, 2021
- An effective main menuOct 01, 2020
- Making the menu shineMay 30, 2020
- Floating SkiesMay 23, 2020
- Demo and showcase at PoCInPlayMay 23, 2020
- Using Unity's new Input SystemMay 23, 2020
- Well, it has Character(s), part 2May 23, 2020
- Well, it has Character(s)May 23, 2020
- The OverGemMay 23, 2020
Leave a comment
Log in with itch.io to leave a comment.