Castle Wars Update 2.3 - First-Person Melee Combat, Split Screen, and a Minor Refactor
By Frank “Weekie” Podraza, Apr. 16, 2023
Hey there! I’ve been working on Castle Wars, and the combat system thus far has been kind of… lacking.
Basic Animations
As far as animations go, there was a primary attack and an idle animation. It was the bare minimum to try and get the attacks dealing damage, but there were no secondary and melee attacks and no blocking/sheathing ability.
I set out to add more animations, as well as improve the current ones to feel much better. This also required overhauling lunging, the hit detection system, adding procedural weapon sway, and a lot of research.
I figured my first step was to add arms. I had an arms model lying around from a NatureManufacturer asset I acquired in a humble bundle a while ago. I hope using it makes me feel less buyer’s remorse.
Unity has a package called ‘Animation Rigging’ which has a nice bone and Inverse Kinematics (IK) system, so I added that package and rigged the arms. It gives me these two target points for each arm that I can move to where I want the hands to be and the IK system will do the rest of the work for me.
I was then able to quickly animate a…
- New primary attack
- A secondary attack
- A ‘melee’ attack (a punch)
- To blocking
- From blocking
- A blocking loop
- Unsheathing
- Sheathing
The animations still weren’t 100%, but maybe 40%. I’m sure this will not come back to bite me later.
Animation Controller
Here is the layout of the Animation Controller.
The general layout is that any state (including the beginning state) can go to unsheathing, which then goes to idle. From idle, an attack can take place, the player can start blocking, or sheathe the sword.
When the player is attacking, blocking, or the sword is sheathed, the sword will stay in that state until updated by the weapon controller.
Weapon Sway
Rather than attempting to animate weapon sway manually, I decided to procedurally animate all of it. The weapon’s sway position is calculated and then applied before every rendered frame. It is calculated by aggregating a bunch of individual functions which return vectors.
Sheathing
The sheathing is a necessity, the sword will start sheathed, and then enter the idle state. If the player climbs a ladder or swims in water the sword will be sheathed, which disables attacks and blocking for the duration of the movement.
Better Animations
So you know how that my animating wouldn’t come back to bite me? It did. It just felt off. I couldn’t exactly figure out why it felt off, but I knew that it was. The animations felt floaty, and like the sword had no air, and that no effort was being put into it.
I decided that my lack of playing sword-combat games was likely the cause of this, so I put together a required reading list. (Feel free to message me with more suggestions). The list was:
- Halo Reach (where I got the idea for the game, hadn’t played in a while)
- Minecraft (Not much to learn from this one, got sucked in for a couple of weeks anyways)
- Breath of the Wild (I picked up a switch in the early winter, god this is such a good game)
- Skyrim (I tried, I promise, I really just can’t seem to get into it)
- Valheim
Breath of the Wild was where I first noticed how short the actual attack animations are. I started examining Halo Reach energy sword swing animations, and I cataloged the pacing proportions of each part of the swing animation. The swing itself was only a sixth of each animation. The first third was the windup, then the next sixth was the swing, and the remaining half was the follow-through and reset.
There was also a hint of camera shake which indicated that the player’s head was getting pulled by the momentum of the swing. Also, the sword was pulled off-screen during the wind-up and went fully off-screen after the swing itself. This is the sell the breadth of the swing, as well as to make the animator’s life easier.
I also added sounds. You need sounds to sell visuals. I added sounds for:
- The swing “swooshing” the air around it.
- Vocal effort from the player character (this doesn’t play every swing, because that would get annoying)
- Enemy hit (flesh) sounds
- Surface hit sounds (sword, wall, ground)
Most of these elements are subtle enough that I usually don’t notice them, but subconsciously my brain did.
New Hit Detection
I wanted to revamp the hit detection. It worked by attaching a collider to the sword and letting that collider pass through things in the path of the sword, applying damage to what it collided with. This means that both: changing the animations changes hit detection, and the hit detection would be affected by the weapon sway.
To remember this I created a collider that is parented to the player, which isn’t affected by weapon sway, and plays an animation to move the collider. It generally matches the swing motion, but I can slightly modify the swings to perfect the animations.
Lunging Overhaul
I feel that lunging is necessary since it is integral to making the Halo sword combat work. Halo is an arcade shooter, and thus it doesn’t have melee combat mechanics that punish you very hard. It has lunging to make sure that your attacks land.
I already had lunging. It was clunky, after detecting a lunge target, the player would lunge to the target’s position over 0.3 seconds. This had 3 main issues.
- The lunge would be 0.3 seconds regardless of distance, which means that extremely short distances would lock the player out of attacking of 0.3 seconds, which is noticeable. The player now attacks when in range of the attack
- The lunge target could move, but the player would continue to move to the position the target was when the lunge began. This is evidence I built lunging with static enemies.
- Because the lunge target could move, this meant that the player could overlap the target if the target moved toward the player. Lunging now ends when the player is about to overlap with the target.
Lunging is also now a per-attack feature. I may reverse this eventually, but it will probably add balancing ability.
Sword Drops and next time
I also implemented sword pickup objects. Right now interaction just picks up the object. They do not swap the player’s active weapon yet. I am going to implement this once I’ve added more swords.
Speaking of more swords. I am going to add 4 more swords. That should be enough to play and test the game. There will be a short video on each sword, which will be linked below. The 4 swords I’ll be adding are:
- K-Type (Katana)
- G-Type (Glaive)
- E-Type (Energy Sword)
- S&S-Type (Sword and Shield pair)
Quick record time/Recommendations:
- Benches - Their singles (Violent, LA Friends, It Doesn’t Have to Change, Mephisto’s Waltz, Common Sense, I Don’t Make Me)
- The Strokes - Comedown Machine
- Black Country, New Road - Live at Bush Hall
- The Velvet Underground - Loaded