Basic Punch for character and start of Enemy Punch

This commit is contained in:
charnet3d 2024-01-28 12:16:59 +01:00
parent 00711c681e
commit b0df82cfd7
35 changed files with 320 additions and 56 deletions

View File

@ -334,3 +334,60 @@ BuildToolsOverride=
bStreamLandscapeMeshLODs=False bStreamLandscapeMeshLODs=False
bEnableDomStorage=False bEnableDomStorage=False
[/Script/Engine.CollisionProfile]
-Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision",bCanModify=False)
-Profiles=(Name="BlockAll",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldStatic",CustomResponses=,HelpMessage="WorldStatic object that blocks all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
-Profiles=(Name="OverlapAll",CollisionEnabled=QueryOnly,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
-Profiles=(Name="BlockAllDynamic",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldDynamic",CustomResponses=,HelpMessage="WorldDynamic object that blocks all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
-Profiles=(Name="OverlapAllDynamic",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
-Profiles=(Name="IgnoreOnlyPawn",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that ignores Pawn and Vehicle. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="OverlapOnlyPawn",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ",bCanModify=False)
-Profiles=(Name="Pawn",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Pawn",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object. Can be used for capsule of any playerable character or AI. ",bCanModify=False)
-Profiles=(Name="Spectator",CollisionEnabled=QueryOnly,ObjectTypeName="Pawn",CustomResponses=((Channel="WorldStatic",Response=ECR_Block),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Pawn object that ignores all other actors except WorldStatic.",bCanModify=False)
-Profiles=(Name="CharacterMesh",CollisionEnabled=QueryOnly,ObjectTypeName="Pawn",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object that is used for Character Mesh. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="PhysicsActor",CollisionEnabled=QueryAndPhysics,ObjectTypeName="PhysicsBody",CustomResponses=,HelpMessage="Simulating actors",bCanModify=False)
-Profiles=(Name="Destructible",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Destructible",CustomResponses=,HelpMessage="Destructible actors",bCanModify=False)
-Profiles=(Name="InvisibleWall",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldStatic object that is invisible.",bCanModify=False)
-Profiles=(Name="InvisibleWallDynamic",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that is invisible.",bCanModify=False)
-Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that is used for trigger. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="UI",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Block),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
+Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision")
+Profiles=(Name="BlockAll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=,HelpMessage="WorldStatic object that blocks all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="OverlapAll",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="BlockAllDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=,HelpMessage="WorldDynamic object that blocks all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="OverlapAllDynamic",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that overlaps all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="IgnoreOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that ignores Pawn and Vehicle. All other channels will be set to default.")
+Profiles=(Name="OverlapOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ")
+Profiles=(Name="Pawn",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object. Can be used for capsule of any playerable character or AI. ")
+Profiles=(Name="Spectator",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="WorldStatic"),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Pawn object that ignores all other actors except WorldStatic.")
+Profiles=(Name="CharacterMesh",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object that is used for Character Mesh. All other channels will be set to default.")
+Profiles=(Name="PhysicsActor",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=,HelpMessage="Simulating actors")
+Profiles=(Name="Destructible",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Destructible",CustomResponses=,HelpMessage="Destructible actors")
+Profiles=(Name="InvisibleWall",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldStatic object that is invisible.")
+Profiles=(Name="InvisibleWallDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that is invisible.")
+Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that is used for trigger. All other channels will be set to default.")
+Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.")
+Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.")
+Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ")
+DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Ignore,bTraceType=True,bStaticObject=False,Name="Enemy")
-ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall")
-ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn")
-ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic")
-ProfileRedirects=(OldName="SkeletalMeshActor",NewName="PhysicsActor")
-ProfileRedirects=(OldName="InvisibleActor",NewName="InvisibleWallDynamic")
+ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall")
+ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn")
+ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic")
+ProfileRedirects=(OldName="SkeletalMeshActor",NewName="PhysicsActor")
+ProfileRedirects=(OldName="InvisibleActor",NewName="InvisibleWallDynamic")
-CollisionChannelRedirects=(OldName="Static",NewName="WorldStatic")
-CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic")
-CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle")
-CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn")
+CollisionChannelRedirects=(OldName="Static",NewName="WorldStatic")
+CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic")
+CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle")
+CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/SideScroller/Animations/Combat/Punch1.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/SideScroller/Animations/Combat/Punch_Montage.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/SideScroller/Blueprints/BP_EnemyCharacter.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/SideScroller/Maps/ExampleMap.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -3,3 +3,26 @@
#include "EnemyCharacter.h" #include "EnemyCharacter.h"
AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
void AEnemyCharacter::BeginPlay()
{
/*GetWorldTimerManager().SetTimer(AutoPunch, this, &AEnemyCharacter::StartPunch,
1.f);*/
}
void AEnemyCharacter::Tick(float DeltaTime)
{
}
void AEnemyCharacter::StartPunch()
{
if (CanAttack)
UE_LOG(LogTemp, Warning, TEXT("Enemy StartPunch()"));
Super::StartPunch();
GetWorldTimerManager().SetTimer(AutoPunch, this, &AEnemyCharacter::StartPunch,
1.f);
}

View File

@ -4,8 +4,12 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "FunnyPrinceCharacter.h" #include "FunnyPrinceCharacter.h"
#include "Logging/LogMacros.h"
#include "EnemyCharacter.generated.h" #include "EnemyCharacter.generated.h"
DECLARE_LOG_CATEGORY_EXTERN(LogTemplateEnemyCharacter, Log, All);
/** /**
* *
*/ */
@ -13,5 +17,22 @@ UCLASS()
class FUNNYPRINCE_API AEnemyCharacter : public AFunnyPrinceCharacter class FUNNYPRINCE_API AEnemyCharacter : public AFunnyPrinceCharacter
{ {
GENERATED_BODY() GENERATED_BODY()
public:
AEnemyCharacter(const FObjectInitializer& ObjectInitializer);
protected:
// To add mapping context
virtual void BeginPlay() override;
// To add mapping context
virtual void Tick(float DeltaTime) override;
virtual void StartPunch() override;
private:
FTimerHandle AutoPunch;
public:
}; };

View File

@ -4,8 +4,11 @@
#include "FunnyPrinceCharacter.h" #include "FunnyPrinceCharacter.h"
#include "SSTCharacterMovementComponent.h" #include "SSTCharacterMovementComponent.h"
#include "Components/InputComponent.h" #include "Components/InputComponent.h"
#include "Components/ArrowComponent.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "InputActionValue.h" #include "InputActionValue.h"
#include "Engine/DamageEvents.h"
#include "EnemyCharacter.h"
DEFINE_LOG_CATEGORY(LogTemplateFunnyPrinceCharacter); DEFINE_LOG_CATEGORY(LogTemplateFunnyPrinceCharacter);
@ -16,7 +19,18 @@ DEFINE_LOG_CATEGORY(LogTemplateFunnyPrinceCharacter);
AFunnyPrinceCharacter::AFunnyPrinceCharacter(const FObjectInitializer& ObjectInitializer) AFunnyPrinceCharacter::AFunnyPrinceCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer) : Super(ObjectInitializer)
{ {
StartAttack = CreateDefaultSubobject<UArrowComponent>("StartAttack");
StartAttack->SetupAttachment(RootComponent);
StartAttack->SetRelativeLocation(FVector(60.f, 0.f, 40.f));
StartAttack->SetArrowSize(0.5f);
StartAttack->SetArrowLength(30.f);
EndAttack = CreateDefaultSubobject<UArrowComponent>("EndAttack");
EndAttack->SetupAttachment(RootComponent);
EndAttack->SetRelativeLocation(FVector(105.f, 0.f, 40.f));
EndAttack->SetArrowSize(0.5f);
EndAttack->SetArrowLength(30.f);
} }
void AFunnyPrinceCharacter::BeginPlay() void AFunnyPrinceCharacter::BeginPlay()
@ -37,10 +51,51 @@ void AFunnyPrinceCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInp
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) { if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) {
// Punching // Punching
EnhancedInputComponent->BindAction(PunchAction, ETriggerEvent::Started, this, &AFunnyPrinceCharacter::Punch); EnhancedInputComponent->BindAction(PunchAction, ETriggerEvent::Started, this, &AFunnyPrinceCharacter::StartPunch);
} }
} }
void AFunnyPrinceCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
float AFunnyPrinceCharacter::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator,
AActor* DamageCauser)
{
float DamageToApply = Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
DamageToApply = FMath::Min(Health, DamageToApply);
Health -= DamageToApply;
if (Health <= 0)
{
Health = 0;
/*ASimpleShooterGameModeBase* GameMode = GetWorld()->GetAuthGameMode<ASimpleShooterGameModeBase>();
if (GameMode)
{
GameMode->PawnKilled(this);
}
DetachFromControllerPendingDestroy();
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);*/
}
UE_LOG(LogTemp, Warning, TEXT("Actor hit for %f damage. Current HP: %f"), DamageToApply, Health);
return DamageToApply;
}
bool AFunnyPrinceCharacter::IsDead() const
{
return (Health <= 0);
}
float AFunnyPrinceCharacter::GetHealthPercent() const
{
return Health / MaxHealth;
}
bool AFunnyPrinceCharacter::CanJumpInternal_Implementation() const bool AFunnyPrinceCharacter::CanJumpInternal_Implementation() const
{ {
USSTCharacterMovementComponent* Movement = Cast<USSTCharacterMovementComponent>(GetCharacterMovement()); USSTCharacterMovementComponent* Movement = Cast<USSTCharacterMovementComponent>(GetCharacterMovement());
@ -53,7 +108,61 @@ bool AFunnyPrinceCharacter::CanJumpInternal_Implementation() const
return Super::CanJumpInternal_Implementation(); return Super::CanJumpInternal_Implementation();
} }
void AFunnyPrinceCharacter::Punch() void AFunnyPrinceCharacter::StartPunch()
{ {
GetCharacterMovement()->IsFalling() if (!CanAttack) return;
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance && PunchMontage)
{
UE_LOG(LogTemp, Warning, TEXT("StartPunch()"));
//CanAttack = false;
if (Enemy && Enemy->GetMesh()->GetAnimInstance())
{
Enemy->GetMesh()->GetAnimInstance()->Montage_Play(Enemy->PunchMontage);
}
AnimInstance->Montage_Play(PunchMontage);
//AnimInstance->Montage_JumpToSection(FName("StartFire"));
}
//GetCharacterMovement()->IsFalling();
}
void AFunnyPrinceCharacter::FinishPunching()
{
CanAttack = true;
}
void AFunnyPrinceCharacter::PunchHitTrace()
{
// Trace hit
FHitResult PunchTraceHit;
if (StartAttack && EndAttack)
{
FVector start = StartAttack->GetSocketLocation(FName());
FVector end = EndAttack->GetSocketLocation(FName());
FCollisionQueryParams Params;
Params.AddIgnoredActor(this);
bool bSuccess = GetWorld()->LineTraceSingleByChannel(PunchTraceHit, start, end, ECollisionChannel::ECC_GameTraceChannel1, Params);
if (bSuccess)
{
AActor* HitActor = PunchTraceHit.GetActor();
if (HitActor)
{
FPointDamageEvent DamageEvent(PunchDamage, PunchTraceHit, end - start, nullptr);
HitActor->TakeDamage(PunchDamage, DamageEvent, GetController(), this);
}
}
/*UE_LOG(LogTemp, Warning, TEXT("TraceHit from %f %f %f to %f %f %f"),
start.X,
start.Y,
start.Z,
end.X,
end.Y,
end.Z);*/
// (World, Start, End, Color, Persistent Lines, Life Time, Depth Priority, Thickness)
DrawDebugLine(GetWorld(), start, end, FColor(255, 0, 0), false, 1, 0, 5);
}
} }

View File

@ -5,8 +5,11 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "SSTCharacter.h" #include "SSTCharacter.h"
#include "Logging/LogMacros.h" #include "Logging/LogMacros.h"
#include "FunnyPrinceCharacter.generated.h" #include "FunnyPrinceCharacter.generated.h"
class AEnemyCharacter;
DECLARE_LOG_CATEGORY_EXTERN(LogTemplateFunnyPrinceCharacter, Log, All); DECLARE_LOG_CATEGORY_EXTERN(LogTemplateFunnyPrinceCharacter, Log, All);
/** /**
@ -20,25 +23,70 @@ class FUNNYPRINCE_API AFunnyPrinceCharacter : public ASSTCharacter
public: public:
AFunnyPrinceCharacter(const FObjectInitializer& ObjectInitializer); AFunnyPrinceCharacter(const FObjectInitializer& ObjectInitializer);
protected:
// APawn interface // APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
// To add mapping context // To add mapping context
virtual void BeginPlay(); virtual void Tick(float DeltaTime) override;
protected:
// To add mapping context
virtual void BeginPlay() override;
virtual float TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, AActor* DamageCauser) override;
UFUNCTION(BlueprintPure)
bool IsDead() const;
UFUNCTION(BlueprintPure)
float GetHealthPercent() const;
virtual bool CanJumpInternal_Implementation() const override; virtual bool CanJumpInternal_Implementation() const override;
void Punch(); virtual void StartPunch();
UFUNCTION(BlueprintCallable)
void FinishPunching();
UFUNCTION(BlueprintCallable)
void PunchHitTrace();
/** Punch Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = true))
TObjectPtr<class UInputAction> PunchAction = nullptr;
/** Punch Montage */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
UAnimMontage* PunchMontage = nullptr;
/** Punch Start Position */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
UArrowComponent* StartAttack = nullptr;
/** Punch End Position */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
UArrowComponent* EndAttack = nullptr;
/** Punch Input Action */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat, meta = (AllowPrivateAccess = true))
bool CanAttack = true;
UPROPERTY(EditDefaultsOnly)
float MaxHealth = 100;
/** Current Health */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat, meta = (AllowPrivateAccess = true))
float Health = 100;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
float PunchDamage = 10;
/** Punch End Position */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
TSoftObjectPtr<AEnemyCharacter> Enemy = nullptr;
private: private:
/** Punch Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputAction> PunchAction;
/** Punch Input Action */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat, meta = (AllowPrivateAccess = "true"))
bool IsPunching;
public: public:
}; };