Update Character for Damage Control
This commit is contained in:
parent
cf00ad90c2
commit
75c067e0d1
@ -67,11 +67,30 @@ void ASeagullGameCharacter::BeginPlay()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ASeagullGameCharacter::DamagePlayer(float DamageAmount)
|
||||||
|
{
|
||||||
|
CurrentHealth -= DamageAmount;
|
||||||
|
if (CurrentHealth <= 0)
|
||||||
|
{
|
||||||
|
CurrentHealth = 0;
|
||||||
|
OnPlayerDeath.Broadcast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASeagullGameCharacter::HealPlayer(float HealAmount)
|
||||||
|
{
|
||||||
|
CurrentHealth += HealAmount;
|
||||||
|
if (CurrentHealth > MaxHealth)
|
||||||
|
{
|
||||||
|
CurrentHealth = MaxHealth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ASeagullGameCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
void ASeagullGameCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||||
{
|
{
|
||||||
// Set up action bindings
|
// Set up action bindings
|
||||||
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) {
|
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent))
|
||||||
|
{
|
||||||
//Jumping
|
//Jumping
|
||||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
|
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
|
||||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
|
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
|
||||||
@ -81,7 +100,6 @@ void ASeagullGameCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInp
|
|||||||
|
|
||||||
//Looking
|
//Looking
|
||||||
// EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ATP_ThirdPersonCharacter::Look);
|
// EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ATP_ThirdPersonCharacter::Look);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +108,6 @@ void ASeagullGameCharacter::Move(const FInputActionValue& Value)
|
|||||||
// input is a Vector2D
|
// input is a Vector2D
|
||||||
FVector2D MovementVector = Value.Get<FVector2D>();
|
FVector2D MovementVector = Value.Get<FVector2D>();
|
||||||
|
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Move: %f, %f"), MovementVector.X, MovementVector.Y));
|
|
||||||
|
|
||||||
if (Controller != nullptr)
|
if (Controller != nullptr)
|
||||||
{
|
{
|
||||||
// find out which way is forward
|
// find out which way is forward
|
||||||
@ -100,7 +116,7 @@ void ASeagullGameCharacter::Move(const FInputActionValue& Value)
|
|||||||
|
|
||||||
// get forward vector
|
// get forward vector
|
||||||
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
||||||
|
|
||||||
// get right vector
|
// get right vector
|
||||||
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
||||||
|
|
||||||
|
@ -13,6 +13,11 @@ class ASeagullGameCharacter : public ACharacter
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnPlayerDeath);
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintAssignable, Category = "Events")
|
||||||
|
FOnPlayerDeath OnPlayerDeath;
|
||||||
|
|
||||||
ASeagullGameCharacter();
|
ASeagullGameCharacter();
|
||||||
|
|
||||||
// Called every frame.
|
// Called every frame.
|
||||||
@ -40,6 +45,18 @@ public:
|
|||||||
|
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Health")
|
||||||
|
float MaxHealth = 100;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Health")
|
||||||
|
float CurrentHealth;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Health")
|
||||||
|
float DefaultHealth = 100;
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Health")
|
||||||
|
void DamagePlayer(float DamageAmount);
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Health")
|
||||||
|
void HealPlayer(float HealAmount);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// APawn interface
|
// APawn interface
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
@ -57,5 +74,4 @@ private:
|
|||||||
/** Camera boom positioning the camera above the character */
|
/** Camera boom positioning the camera above the character */
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||||
class USpringArmComponent* CameraBoom;
|
class USpringArmComponent* CameraBoom;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -9,18 +9,4 @@ ASeagullGameGameMode::ASeagullGameGameMode()
|
|||||||
{
|
{
|
||||||
// use our custom PlayerController class
|
// use our custom PlayerController class
|
||||||
PlayerControllerClass = ASeagullGamePlayerController::StaticClass();
|
PlayerControllerClass = ASeagullGamePlayerController::StaticClass();
|
||||||
|
|
||||||
// set default pawn class to our Blueprinted character
|
|
||||||
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/TopDown/Blueprints/BP_TopDownCharacter"));
|
|
||||||
if (PlayerPawnBPClass.Class != nullptr)
|
|
||||||
{
|
|
||||||
DefaultPawnClass = PlayerPawnBPClass.Class;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set default controller to our Blueprinted controller
|
|
||||||
static ConstructorHelpers::FClassFinder<APlayerController> PlayerControllerBPClass(TEXT("/Game/TopDown/Blueprints/BP_TopDownPlayerController"));
|
|
||||||
if(PlayerControllerBPClass.Class != NULL)
|
|
||||||
{
|
|
||||||
PlayerControllerClass = PlayerControllerBPClass.Class;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user