Construct the construction of the world and

Haha, no kidding. In this installment we implement a Shinra Tensei like skill. The ability can fly enemies around the character and make them feel pain!

First, describe the implementation process of skills:

  1. Launch skills, PlayMontageAndWait.
  2. Get enemy characters centered around the role and within the sphere of the collision with TargetActor and transfer the data to Gameplay Ability.
  3. After receiving Anim Notify, all enemies in the data will be drawn to the character.
  4. After receiving Push Notify, Push the enemy away and let them feel the pain.

TargetActor

TargetActor is used to assist Ability in target selection and can be used for network data transmission. According to the source code, TargetActor is resource-intensive. But in theory we don’t have a lot of choice of targets to launch at the same time. At the same time, the official documentation also emphasizes that their implementation of the base class is unreliable, and recommends that you implement similar functionality through subclass to avoid consumption and security.

/** * TargetActors are spawned to assist with ability targeting. They are spawned by ability tasks and create/determine the outgoing targeting data passed from one task to another * * WARNING: These actors are spawned once per ability activation and in their default form are not very efficient * For most game s you will need to subclass and heavily modify this actor, or you will want to implement similar functions in a game-specific actor or blueprint to avoid actor spawn costs * This class is not well tested by internal games, but it is a useful class to look at to learn how target replication occurs */
Copy the code

Code implementation

This section implements a class that takes actors in a sphere centered around the release of the performer and feeds this data to the skill.

First of all new GameplayAbilityTargetActor derived class. Here we have a name for it directly AbilityShinraTenseiTargetActor.

Open the AbilityShinraTenseiTargetActor. H. Start by creating a derived class in public. Rewrite the two methods StartTargeting and ConfirmTargetingAndContinue, then create a float objects, showed that the release of the skills.

UCLASS(a)class GAS_LEARN_API AAbilityShinraTenseiTargetActor : public AGameplayAbilityTargetActor
{
	GENERATED_BODY(a)public:
	AAbilityShinraTenseiTargetActor(a);virtual void StartTargeting(UGameplayAbility* Ability) override;

	virtual void ConfirmTargetingAndContinue(a) override;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Ability Settings", meta=(ExposeOnSpawn=true))
	float Radius;
};
Copy the code

Rewrite StartTargeting

This function is run when TargetActor starts looking for the target. OwningAbility as the name implies, the value is the Ability to have this TargetActor. MasterPC is the Controller that controls the Character. We didn’t use CharacterController in the tutorial. Our logic is implemented in Character, so we don’t really need to assign this object. SourceActor refers to the Actor (nesting doll) that has the Ability to call TargeActor. The three objects are defined in the base class GameplayAbilityTargetActor finish.

void AAbilityShinraTenseiTargetActor::StartTargeting(UGameplayAbility* Ability)
{
	OwningAbility = Ability;
	MasterPC = Cast<APlayerController>(Ability->GetOwningActorFromActorInfo() - >GetInstigatorController());
	SourceActor = Ability->GetOwningActorFromActorInfo(a); }Copy the code

Rewrite ConfirmTargetingAndContinue

What we do in the function is get the enemies within the skill range and return the data to Ability for processing.

The process is as follows:

  1. The AbilityStartLocation variable is used to store the location where the skill is released, OverlapResults is used to store the results of the spherical collision detector, and OverlapActors is used to record the data that is ultimately returned to the skill.
  2. Create a spherical collider with GetWorld()->OverlapMultiByObjectType. If successful, the result of collision detection will be written to OverlapResults.
  3. If the collision is successful, the Actor in the resulting collision is deposited into the OverlapActors.
  4. If the length of the OverlapActors is greater than zero, the valid data is broadcast through the Delegate. This data is available in Ability.
void AAbilityShinraTenseiTargetActor::ConfirmTargetingAndContinue(a)
{
	// The object used by the function
	FVector AbilityStartLocation = FVector::ZeroVector;

	TArray<FOverlapResult> OverlapResults;
	TArray<TWeakObjectPtr<AActor>> OverlapActors;

	// Build params for collision detection
	FCollisionQueryParams QueryParams;
	QueryParams.bTraceComplex = false;
	QueryParams.bReturnPhysicalMaterial = false;
	if(SourceActor)
	{
		QueryParams.AddIgnoredActor(SourceActor->GetUniqueID());
		AbilityStartLocation = SourceActor->GetActorLocation(a); }// Build a spherical collision body for collision detection
	bool TryOverlap = GetWorld() - >OverlapMultiByObjectType(
		OverlapResults,
		AbilityStartLocation,
		FQuat::Identity,
		FCollisionObjectQueryParams(ECC_Pawn),
		FCollisionShape::MakeSphere(Radius),
		QueryParams);

	// If a collision occurs, write the colliding actor to the OverlapActors
	if(TryOverlap)
	{
		for(const FOverlapResult& Result: OverlapResults)
		{
			APawn* OverlappedPawn = Cast<APawn>(Result.Actor);
			if(IsValid(OverlappedPawn))
			{
				OverlapActors.AddUnique(OverlappedPawn); }}}// If the OverlapActors have data, broadcast it over the delegate
	if(OverlapActors.Num(a) >0)
	{
		const FGameplayAbilityTargetDataHandle TargetData = StartLocation.MakeTargetDataHandleFromActors(OverlapActors);
		TargetDataReadyDelegate.Broadcast(TargetData); }}Copy the code

Role of the blueprint

Open the character blueprint you created. A new Custom Event, called Push Character, implements the Impluse of a specified force in a specified direction that can be used to knock or pull the role. You do this by calling the Add Impulse function in the Character Movement Component.

Create a new Custom Event named ShinraTensei that has a bool input. This event is used to indicate the status of a skill, and when called with true, it indicates that the enemy needs to be pulled towards you. When this event is called and entered as false, the enemy needs to be shot away.

When the input is true, then send your ASC a Gameplay Event, labeled Ability. ShinraTensei. Pull, shows that the enemy to Pull role. When the input is false, send the Event with a tag Ability. ShinraTensei. Push, indicates that the blow fly to the enemy.

Montage Notify

Create Montage with an animation of your own choosing, and then create a new Notify in the appropriate place, naming it Pull Character and Push Character.

Open the character animation blueprint. After receiving Pull Notify, ShinraTensei(State=true) is called. After receiving Push Notify, call ShinraTensei(State=false)

Shinra Tensei Ability

Gameplay Effect

Create the desired Gameplay Effect. The effect is to deal damage to enemies. I went straight to the simplest method, dealing 50 damage directly with Scalable Float.

Gameplay Cue

Create a Gameplay Cue where we play lines through GC.

The implementation generates a sound on the Root Component of the role that plays the skill voice. Be sure to set the Tag.

BP_TargetData

Create a blueprint derived class of the TargetActor implemented earlier.

Gameplay Ability

Create Gameplay ability named GA_ShinraTensei. Explain the process in the first diagram.

  1. Play montage via Task PlayMontageAndWait
  2. Call the GC that plays the sound by adding GameplayCue to Owner.
  3. It then waits for the Event sent in the Character blueprint, the Pull Character Notify in Montage.
  4. Call Task Wait Target Data and select the class BP_ShinraTensei_TargetActor we just created. Note that the skill range is set to 1000.

The second picture:

  1. After receiving the Valid Data sent by TargetActor, extract the Actor in it.
  2. The direction of the pull role is calculated by subtracting two vectors of position information.
  3. Call Push Character to pull the role.

The third chart:

  1. Wait for the Push Character Notify in Montage.
  2. In the same way, the difference is that the previous position information is subtracted and the order is reversed. At the same time, a UpVector is added in the direction, which is responsible for making the character fly up to the sky as well as backward.
  3. Applying Gameplay Effect causes Gameplay damage.

test

GAS Primer collection