디버깅 드로잉
디버깅 드로잉 기능을 사용하기 위해
[.h]
UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = Attack, Meta = (AllowPrivateAccess = true))
float AttackRange;
UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = Attack, Meta = (AllowPrivateAccess = true))
float AttackRadius;
[.cpp]
#include "ABCharacter.h"
#include "ABAnimInstance.h"
#include "DrawDebugHelpers.h" //추가
AABCharacter::AABCharacter()
{}
...
void AABCharacter::AttackCheck()
{
FHitResult HitResult;
FCollisionQueryParams Params(NAME_None, false, this);
bool bResult = GetWorld()->SweepSingleByChannel(
HitResult,
GetActorLocation(),
GetActorLocation() + GetActorForwardVector() * AttackRange,
FQuat::Identity,
ECollisionChannel::ECC_GameTraceChannel2,
FCollisionShape::MakeSphere(AttackRadius),
Params);
#if ENABLE_DRAW_DEBUG
FVector TraceVec = GetActorForwardVector() * AttackRange;
FVector Center = GetActorLocation() + TraceVec * 0.5f;
float HalfHeight = AttackRange * 0.5f + AttackRadius;
FQuat CapsuleROt = FRotationMatrix::MakeFromZ(TraceVec).ToQuat();
FColor DrawColor = bResult ? FColor::Green : FColor::Red;
float DebugLifeTime = 5.0f;
DrawDebugCapsule(GetWorld(),
Center,
HalfHeight,
AttackRadius,
CapsuleRot,
DrawColor,
false,
DebugLifeTime );
#endif
if (bResult)
{
if (HitResult.Actor.IsValid())
{
printf("%s",*HitResult.Actor->GetName());
}
}
}
대미지 프레임워크
- 언리얼 엔진의 액터 클래스 AActor는 TakeDamage라는 함수가 구현돼 있고, 4개의 인자가 있다
- DamageAmount : 전달할 대미지의 세기
- DamageEvent : 대미지 종류
- EventInstigator : 공격 명령을 내린 가해자
- DamageCauser : 대미지 전달을 위해 사용한 도구
void AABCharacter::AttackCheck()
{
...
if (bResult)
{
if (HitResult.Actor.IsValid())
{
//printf("%s",*HitResult.Actor->GetName());
FDamageEvent DamageEvnet;
HitResult.Actor->TakeDamage(50.0f, DamageEvnet,GetController(),this);
}
}
}
//h
class KGAME_API AABCharacter : public ACharacter
{
virtual float TakeDamage(float DamageAmout, struct FDamageEvent const& DamageEvent,
class AController* EventInstigator, AActor* DamageCauser) override;
}
//cpp
float AABCharacter::TakeDamage(float DamageAmout, struct FDamageEvent const& DamageEvent,
class AController* EventInstigator, AActor* DamageCauser)
{
float FinalDamage = Super::TakeDamage(DamageAmout, DamageEvent, EventInstigator, DamageCauser);
if (FinalDamage > 0.0f)
{
ABAnim->SetDeadAnim();
SetActorEnableCollision(false);
}
return FinalDamage;
}
사망시 애니메이션 추가
class KGAME_API UABAnimInstance : public UAnimInstance
{
..
void SetDeadAnim() { IsDead = true; }
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Pawn, Meta = (AllowPrivateAccess = true))
bool IsDead;
};
//cpp
float AABCharacter::TakeDamage(float DamageAmout, struct FDamageEvent const& DamageEvent,
class AController* EventInstigator, AActor* DamageCauser)
{
float FinalDamage = Super::TakeDamage(DamageAmout, DamageEvent, EventInstigator, DamageCauser);
if (FinalDamage > 0.0f)
{
ABAnim->SetDeadAnim();
SetActorEnableCollision(false);
}
return FinalDamage;
}
}
'Unreal > Game 1 (C++)' 카테고리의 다른 글
14.아이템 상자의 제작 (0) | 2019.05.02 |
---|---|
13.소켓 + 무기액터 (0) | 2019.05.02 |
12.충돌 설정과 대미지 전달 (PART 1) (0) | 2019.05.02 |
11.애니메이션 노티파이 + 콤보 공격 구현 (0) | 2019.05.02 |
10.델리게이트, 다이나믹 , 멀티캐스트 , 다이나믹 멀티, 시그니처 (1) | 2019.05.02 |