Gameplay Ability System introduction (1)- Initial setup
Unreal four Gameplay Ability System Introduction (2)- Common attacks
Gameplay Ability System (3)-UI interaction
Gameplay Ability System introduction (4)- Cure effect
The purpose of this article is to realize a simple attack Ability. Before we begin, let’s first design how the character’s normal attacks are implemented in the blueprint:
- The left mouse button starts the attack event
- Attack has begun. Play Montage.
- Montage has notify, which enables attack collision detection and disables collision detection, similar to damage frames
- If a collision occurs, ApplyDamage is used to deal damage to the enemy
- When montage is played, the attack event ends.
In GAS, we should think of the attack as a complete Ability, so its responsibility should include 2,4,5, and the role itself should be responsible for 1,4. This completes the logical decomposition of the attack.
Let’s start implementing it.
Create an attack Ability
Name it GA_MeleeAttack and open the character blueprint
In BeginPlay, give ordinary attack ability to skill system, and then add events to the left mouse button to start ordinary attack ability.
Implement collision detection of attacks
Open the mesh and you will see that there is a socket named weapon_r in the palm of your right hand. We will add a ball collider to the socket to detect attacks. If you use your own model and do not have this socket, you can add it manually.
After adding, Sphere only needs to detect the collision with Pawn and rewrite begin overlap event
If a collision occurs, then a Gameplay Event is sent to the role itself, which will be responded to in any subsequent attack capability. Note that the Event tag should be ability.melee.DealDamage, indicating that this Event was done in response to a normal attack. Labels need to be added manually. In the data of the event, the damage target needs to be sent as data.
In addition, we expect collision detection to occur only when the attack animation of the protagonist is played, so we need to add two Custum Events and set the Sphere without collision at the beginning.
The code for the role section is complete.
Normal attack Montage
Create an AnimNotify_State. Named AN_Melee
Override the two functions Receive Notify Begin and Receive Notify End.
Then create and open your own attack animation Montage
Add Notify_State, AN_Melee, where appropriate
Normal attack Ability
Next, we need a Gameplay Effect to do any Gameplay damage in order for an attack to work. Named GE_Melee_DealDamge
After opening the blueprint, add a Modifier and change the Health mode to -20
Next open GA_MeleeAttack
The general implementation process is: first add Task, PlayMontageAndWait, then wait for a Gameplay Event, which is the Event that was added in the role and sent after the collision. After receiving the Event, Just apply a gameplayeffect to target, and the GE is the GE_Melee_DealDamage we just implemented.
test
Add a BP_Character to the game and start the game.
Add a test in GA_Melee that prints the health of the character after taking damage
You can see that the hit has gone from 0 to -20. Done, the next article will implement the UI and GAS association.