Create Melee Attacks
With the melee weapons configured, the next step is to create a primary and a secondary attack using the Attack Ability, add these abilities to the player character using Ninja GAS and configure their inputs using Ninja Input.
Add sockets for Melee Scans
Open the Static Mesh for the sword and add three sockets along the blade.
Make sure to prefix your sockets with
sScan
, this prefix will be used soon.Open the Static Mesh for the shield and add one socket at the center.
Again, make sure to prefix your sockets with
sScan
.
Configure the primary attack animation
Create an Animation Montage from an appropriate Animation Sequence that represents the primary attack.
In the Animation Montage, add the Melee Scan Notify State along the frames where the scan should happen.
In the Melee Scan Notify State Details:
Set the Source to
Weapon
and your Scan Channel toWeapon
.Leave the Scan Socket Prefix value unchanged, since it matches the names used in the sword mesh sockets.
Leave the Scan Mode set to Line Trace.
Configure the Weapon query, so it will obtain the sword from the Weapon Manager.
Configure the secondary attack animation
Create an Animation Montage from an appropriate Animation Sequence that represents the secondary attack.
In the Animation Montage, add the Melee Scan Notify State along the frames where the scan should happen.
In the Melee Scan Notify State Details:
Set the Source to
Weapon
and your Scan Channel toWeapon
.Leave the Scan Socket Prefix value unchanged, since it matches the name used in the shield mesh socket.
Set the Scan Mode set to Box Sweep and set dimensions that roughly match the shield's dimensions.
Configure the Weapon query, so it will obtain the shield from the Weapon Manager.
Configure the primary attack ability
Create a new Gameplay Ability for your primary attack, using
CombatAbility_Attack
as the base class.Set the Animation Montage for the primary attack in the Default Animation Montage.
Disable Motion Warping.
Enable debugging.
Add
Ability.Attack.Primary
to the Ability Tags, so it can be used for the activation.Add
Ability.Attack.Secondary
to the list of Block Abilities with Tag, to ensure your attacks won't interrupt each other.
Configure a damage Gameplay Effect
Create a new Gameplay Effect using
CombatEffect_MeleeHit
as the base class. It will be used by the secondary attack.Add
Combat.Effect.Damage.Knockback
to the list of Gameplay Tags Added to the Effect.In the Execution list, add a Calculation Modifier using
Combat.Data.Damage.Multiplier
and set a Scalable Float with a Magnitude of1.5
.
Configure a cost Gameplay Effect
Create a new Gameplay Effect using
GameplayEffect
as the base class. It will be used for by secondary attack.Add the Additional Effects Gameplay Effect Component and include Cancel Stamina Regeneration in the On Application Gameplay Effects list.
Add a Modifier to reduce stamina by
5
.
Configure the secondary attack ability
Create a new Gameplay Ability for your secondary attack, using
CombatAbility_Attack
as the base class.Set the new Damage Gameplay Effect, configured on the previous step, as the Melee Damage Effect Class.
Set the Animation Montage for the secondary attack in the Default Animation Montage.
Disable Motion Warping.
Enable debugging.
Set the new Cost Gameplay Effect, configured on the previous step, as the Cost Effect Class.
Add
Ability.Attack.Secondary
to the Ability Tags, so it can be used for the activation.Add
Ability.Attack.Primary
to the list of Block Abilities with Tag, to ensure your attacks won't interrupt each other.
Add abilities to the Player
Open the Ability Data Asset created for the Player, and add the new abilities.
Configure Player Inputs
Create an Input Action for the Primary Attack. Add a Pressed trigger. Map this Input Action to your Input Mapping Context, assigning the Left Mouse Button as the key. If you have a Gamepad, also map it to the Face Button Left.
Create an Input Action for the Secondary Attack. Add a Pressed trigger. Map this Input Action to your Input Mapping Context, assigning the Right Mouse Button as the key. If you have a Gamepad, also map it to the Face Button Top.
Add two Input Handlers to your Input Setup Data Asset, using the Activate Ability by Tags as the base.
Set the correct Input Actions for each attack, and the correct Ability Tags defined earlier:
Ability.Attack.Primary
andAbility.Attack.Secondary
.When you are done, your Input Setup Data Asset should be similar to the following image.
Test everything
Click the Play button and execute your primary and secondary attacks, pressing the appropriate buttons.
Both your attacks should execute correctly, and you should see scan lines for the debug.