2024-04-24
깃허브! |
---|
https://github.com/ChangJin-Lee/ARproject |
★ https://github.com/ChangJin-Lee/ToonTank |
느낀점
ApplyDamage로 데미지를 적용시키는 방법을 학습했다. 함수로 Damage 관련된 내용이 구현되어 있는게 매우 신기했다. UDamageType에는 Damage에 관련된 아주 많은 내용을 담을 수 있었다.
Name | Description |
---|---|
DamagedActor | Actor that will be damaged. |
BaseDamage | The base damage to apply. |
EventInstigator | Controller that was responsible for causing this damage (e.g. player who shot the weapon) |
DamageCauser | Actor that actually caused the damage (e.g. the grenade that exploded) |
DamageTypeClass | Class that describes the damage that was done. |
void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
AActor* MyOwner = GetOwner();
if(MyOwner==nullptr)
{
Destroy();
return;
}
AController* MyOwnerInstigator = MyOwner->GetInstigatorController();
UClass* DamageTypeClass = UDamageType::StaticClass();
if(OtherActor && OtherActor != this && OtherActor != MyOwner)
{
UGameplayStatics::ApplyDamage(OtherActor, Damage, MyOwnerInstigator, this, DamageTypeClass);
}
Destroy();
}
DamageType.h를 뜯어보면 다음과 같다.
class UDamageType : public UObject
{
GENERATED_UCLASS_BODY()
/** True if this damagetype is caused by the world (falling off level, into lava, etc). */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=DamageType)
uint32 bCausedByWorld:1;
/** True to scale imparted momentum by the receiving pawn's mass for pawns using character movement */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=DamageType)
uint32 bScaleMomentumByMass:1;
/** When applying radial impulses, whether to treat as impulse or velocity change. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = RigidBody)
uint32 bRadialDamageVelChange : 1;
/** The magnitude of impulse to apply to the Actors damaged by this type. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=RigidBody)
float DamageImpulse;
/** How large the impulse should be applied to destructible meshes */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Destruction)
float DestructibleImpulse;
/** How much the damage spreads on a destructible mesh */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Destruction)
float DestructibleDamageSpreadScale;
/** Damage fall-off for radius damage (exponent). Default 1.0=linear, 2.0=square of distance, etc. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=DamageType)
float DamageFalloff;
};
예를들어 게임에서 DamageType_Fire를 데미지를 입은 액터쪽에서 붙일 수 있다.
UDamageType은 immutable data로 다루어져야한다. 그리고 static code functionality를 가져야한다.
Immutable data란 수정, 제거가 절대로 되어선 안되는 엄격하게 관리되는 데이터를 말한다.
class UDamageType : public UObject