1.启动项目,创建爱你CharacterBase的子类
2.创建敌人数据资产
3.创建敌人的ASC
4.创建敌人的CombatComponent
5.打开EnemyCharacter,
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "Character/CharacterBase.h"
#include "WarriorEnemyCharacter.generated.h"class UEnemyCombatComponent;
/*** */
UCLASS()
class ARPG_GRIVITY_API AWarriorEnemyCharacter : public ACharacterBase
{GENERATED_BODY()public:AWarriorEnemyCharacter();//获取自身的CombatComponentFORCEINLINE UEnemyCombatComponent* GetEnemyCombatComponent() const { return EnemyCombatComponent; }protected:UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Combat")UEnemyCombatComponent* EnemyCombatComponent;};
// Fill out your copyright notice in the Description page of Project Settings.#include "Character/WarriorEnemyCharacter.h"#include "Components/Combat/EnemyCombatComponent.h"
#include "GameFramework/CharacterMovementComponent.h"AWarriorEnemyCharacter::AWarriorEnemyCharacter()
{AutoPossessAI = EAutoPossessAI::PlacedInWorldOrSpawned;bUseControllerRotationPitch = false;bUseControllerRotationRoll = false;bUseControllerRotationYaw = false;GetCharacterMovement()->bUseControllerDesiredRotation = false;GetCharacterMovement()->bOrientRotationToMovement = true;GetCharacterMovement()->RotationRate = FRotator(0.f,180.f,0.f);GetCharacterMovement()->MaxWalkSpeed = 300.f;GetCharacterMovement()->bRequestedMoveUseAcceleration = 1000.f;CreateDefaultSubobject<UEnemyCombatComponent>("EnemyCombatComponent");
}
打开EnemyCombatComponent
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "AbilitySystem/Abilities/ARPGGameplayAbility.h"
#include "WarriorEnemyGameplayAbility.generated.h"class UEnemyCombatComponent;
class AWarriorEnemyCharacter;
/*** */
UCLASS()
class ARPG_GRIVITY_API UWarriorEnemyGameplayAbility : public UARPGGameplayAbility
{GENERATED_BODY()public:UFUNCTION(BlueprintPure, Category = "Warrior|Ability")AWarriorEnemyCharacter* GetEnemyCharacterFromActorInfo();UFUNCTION(BlueprintPure, Category = "Warrior|Ability")UEnemyCombatComponent* GetEnemyCombatComponentFromActorInfo();private:TWeakObjectPtr<AWarriorEnemyCharacter> CachedWarriorEnemyCharacter;};
// Fill out your copyright notice in the Description page of Project Settings.#include "AbilitySystem/Abilities/WarriorEnemyGameplayAbility.h"#include "Character/WarriorEnemyCharacter.h"AWarriorEnemyCharacter* UWarriorEnemyGameplayAbility::GetEnemyCharacterFromActorInfo()
{if (!CachedWarriorEnemyCharacter.IsValid()){CachedWarriorEnemyCharacter = Cast<AWarriorEnemyCharacter>(CurrentActorInfo->AvatarActor);}return CachedWarriorEnemyCharacter.IsValid() ? CachedWarriorEnemyCharacter.Get() : nullptr;
}UEnemyCombatComponent* UWarriorEnemyGameplayAbility::GetEnemyCombatComponentFromActorInfo()
{return GetEnemyCharacterFromActorInfo()->GetEnemyCombatComponent();
}
6.启动项目,创建爱你EnemyCHaracter的子类蓝图基类
7.再基于这个蓝图,再创建子类
8.创建敌人模板类动画蓝图
然后创建该动画蓝图的子类,再类设置里需要创建一个混合空间用做移动动画。所以创建一个混合空间。