Added FirstPersonArm from Unreal FPS template. Modified ShootingComponent for using socket in character.
75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Characters/ExoPlayerCharacter.h"
|
|
#include "Characters/Components/ShootingComponent.h"
|
|
#include "GameFramework/CharacterMovementComponent.h"
|
|
#include "Items/AmmoBoxBase.h"
|
|
#include "Items/HealthBoxBase.h"
|
|
#include "Player/InteractionComponent.h"
|
|
|
|
AExoPlayerCharacter::AExoPlayerCharacter()
|
|
{
|
|
GetCharacterMovement()->bSnapToPlaneAtStart = true;
|
|
|
|
InteractionComponent = CreateDefaultSubobject<UInteractionComponent>(TEXT("Interaction Component"));
|
|
ShootingComponent = CreateDefaultSubobject<UShootingComponent>(TEXT("Shooting Component"));
|
|
|
|
Weapon = CreateDefaultSubobject<USkeletalMeshComponent>("Weapon");
|
|
Weapon->SetupAttachment(GetMesh());
|
|
Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
Weapon->bCastDynamicShadow = false;
|
|
Weapon->CastShadow = false;
|
|
Weapon->SetRelativeLocation(FVector(-50.f, 0.f, -90.f));
|
|
|
|
bUseControllerRotationPitch = false;
|
|
bUseControllerRotationYaw = true;
|
|
bUseControllerRotationRoll = false;
|
|
}
|
|
|
|
void AExoPlayerCharacter::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AExoPlayerCharacter::OnActorBeginOverlap);
|
|
}
|
|
|
|
void AExoPlayerCharacter::OnActorBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
|
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
|
{
|
|
if (OtherActor && OtherActor != this)
|
|
{
|
|
if (OtherActor->IsA(AHealthBoxBase::StaticClass()))
|
|
{
|
|
AHealthBoxBase* HealthBox = Cast<AHealthBoxBase>(OtherActor);
|
|
if (HealthBox)
|
|
{
|
|
AddHealthPoints(HealthBox->HealthValue);
|
|
HealthBox->Destroy();
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Zebrano apteczkę"));
|
|
}
|
|
}
|
|
else if (OtherActor->IsA(AAmmoBoxBase::StaticClass()))
|
|
{
|
|
AAmmoBoxBase* AmmoBox = Cast<AAmmoBoxBase>(OtherActor);
|
|
if (AmmoBox)
|
|
{
|
|
if (ShootingComponent->AddAmmo(AmmoBox->AmmoType, AmmoBox->AmmoValue))
|
|
{
|
|
AmmoBox->Destroy();
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Zebrano amunicję"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void AExoPlayerCharacter::AddHealthPoints(float addValue)
|
|
{
|
|
CurrentHealth += addValue;
|
|
|
|
if (CurrentHealth > MaxHealth)
|
|
CurrentHealth = MaxHealth;
|
|
} |