Side Project #8 Milestones, Finally in combat

I saved an interesting reddit post  for the sort of AI that I wanted to implement. It was labeled as sort of a ‘kung-fu movie’ setup where idle enemies take positions on set points and only a set number of them can go into an attacking state and go near the player. I liked how each enemy would be aware of the behavior of the ‘swarm’. I started my implementation with simple states of just being Idle and Attacking. It could even be refined later with further specifying between ranged and melee attackers.

I decided to use Unity’s NavMesh Agents and Surfaces to avoid implementing my own pathfinding. It works for simple point-to-point travel with minimal obstacles. There are some issue with their own avoidance algorithms interfering with each other that needed workarounds, though. The first iteration looked a bit rough with each enemy moving too fast and following the player in a pattern too obviously. But I left it at that for a while to work on other components of the gameplay loop.

I mentioned the Revolver-focused combat and its inpirations before. The first thing a character action game needs is its basic attack combo animations. Research for gun-focused characters started from Gray Ravens, a gacha game I’m still playing for a bit. I planned out an upgradable combo that can go from 2 hits, then 3, 4, and 5 attacks. Monster Hunter’s Bow gameplay is also a huge inspiration for the incremental charging and dodge charging mechanics.

The core design for this gameplay was to have limited bullets, but if you could chain certain actions together like dodging enemies it would build up bonuses to continue your attacks indefinitely. It would also add some rhythm to the resource management. The added Active Reload mechanic really helped push this. By timing a Dodge with the Bullet Reload window, you can get the bonus of refilling the entire magazine. It is actually made easier by the Input Buffering system, but in hectic gameplay there is still a chance of missing the window. A challenge with user experience that I had to solve was to provide proper visual cues on the player character for the Active Reload, instead of relying on UI in the corner of the screen. This included timed particle flashes and extra animation variants.

Back to some more updates for the Camera system. This time I was referencing Devil May Cry 5’s dynamic camera. One thing that I noticed was there was a definite switch between close-up angles and more distant camera setups. It seamlessly transitioned when the player moved away from the target and also when juggling in combos. I really tried to emulate that by taking both the Player and the Target’s 3D screen positions into account and using them as lerp values for multiple camera anchors. The latest iteration has three toggles just to satisfy all use cases: Player, Midpoint, and Target focus. Another improvement and fix for the camera is the target locking. I made sure the raycasts were always accurate in all angles so you could always lock onto a target in the center of the screen. Then there were a few quality of life improvements regarding automated target switching on certain conditions.

With combat on the Player’s side fleshed out more, I was itching to create actual enemy units with AI to play against. The first thing I had to do was decide on a design direction and a theme. I started from just small Insectoids but those didn’t seem threatening enough. I would have to revisit those ideas for smaller swarming enemies. I looked up enemy catalogues from newer action games like Hi-Fi rush. I then stumbled upon pages and pages of Lego mech designs on Pinterest. The blocky shape language was something I could adapt into the game. And there were tons to be inspired from. I’m also trying to integrate the insect themes to the unit classes.

In Blender I figured out how to mix and match meshes and objects with just a single animated Armature. Effectively  being swappable parts for the enemy mechs, and also viable for upgrades and attachments. I still don’t know how to handle the texturing and UV unwrapping for the mixed parts, but that’s a bridge I’ll cross later. I initially made a medium build mech with an arm cannon for the ranged enemy. And a sleeker build with a blade for an arm inspired by Zone of the Enders frames. Of course I needed to animate all the basic states again like idles, hits, attacks, walking. What I saw that was really effective was a 4-way walk cycle. It takes a bit of work to set up with more code and blend trees in Unity but the effect on the game feel was very apparent in making the swarming enemies look focused on the player when they are locked on.

Further improvements to the Swarm AI were a bit counter-intuitive. Instead of making them faster and more aggressive, it actually helped to slow them down. To let them breath for a few moments with more idling and waiting time. It felt more natural that way, some sort of a faked ‘thinking’ state not just always rushing toward the player. I also remade the attacking scripts to fit both melee and ranged routines. Then I reintegrated an old sweeping collider component I had for sword attacks.

With the enemy attacks done, it was time for one of the core mechanics for combat: Dodging. I had already animated the dodge vfx with the transparent mesh duplicates before. Now I had to define set time frames for invincibility and trigger the appropriate reactions on collision. To back this up I designed a Collision Handler that cached the needed interacting Components on initialization. This would also be used for future interactions with HP, Armor, or even Shields.

A lot of units were walking around the field now. And with the player’s mobility in the air it was unavoidable to land on top of the enemies’ heads. The interaction with the colliders actually looked bad. Then I had the thought of making this into another combat mechanic. Just like Mario. With the nearing release of the new Horizon DLC, I remembered its jump-off and aerial attack sequences. I tried to capture the pause before the launch as you brace against the enemy. It also serves as a small breather in the combat’s rhythm.

A lot of the work in combat was done over the long 5-day weekend. I almost couldn’t say it was a break since my brain was full throttle on coding again. I didn’t even dent my gaming backlog. I wanted a breather from the technical game logic so I transitioned into more visual elements of Game Feel ™.

Final Fantasy XVI is also releasing soon. And that game is an overkill with its particles. I wanted some of that juice. There’s something special about the way the sparks swirled around before fading. I found a way to emulate that impact and noise with just the native Particle System. I coupled it with some previous studies of anime hit sparks and streaks to produce satisfying results. Camera shakes were relatively easy with Cinemachine’s Impulse Sources. It was positional and already had curve presets for common things like recoil. A retro hit flashing effect was also injected into the current material shaders, then controlled with material properties. Then I made a global controller for Time Scaling events like hit stops on attacks and slow downs during dodging. This is to keep everying clean and centralized since messing with time can go wrong if you scatter them all over the code.

One more thing to finish the combat loop is enemy HP and damage values. The design for rhythm in combat is evident now as it directly equates to dealing more damage. Missing attacks and reloads resets the charge levels, reducing your overall damage. I hope to push players into making stylish and optimal decisions. Stamina or Poise is also a separate meter for enemies. When it’s broken, they can be opened up to more options like being launched into juggle combos. As the enemy units die they are sent back to the AI Director for recycling. To make clean up smoother I made an interface for components to be triggered on Kill and Respawn to reset values properly.

What’s next is the combat loop on the player’s side. I’m currently missing a ‘pay-off’ mechanic for the positive meter being gained when landing attacks. I am aiming for something similar to Sekiro’s Shinobi Prosthetics system. Unique and meaningful attacks that can be equipped to slots. And then each having their own upgrades. Maybe elemental variants too.

Leave a comment