blaster/Source/Blaster/Pickups/Pickup.cpp

74 lines
2.0 KiB
C++
Raw Normal View History

2022-05-22 15:04:10 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "Pickup.h"
2022-05-22 20:56:28 +00:00
#include "Blaster/Weapon/WeaponTypes.h"
2022-05-22 15:04:10 +00:00
#include "Components/SphereComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Sound/SoundCue.h"
APickup::APickup()
{
PrimaryActorTick.bCanEverTick = true;
bReplicates = true;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
OverlapSphere = CreateDefaultSubobject<USphereComponent>(TEXT("OverlapSphere"));
OverlapSphere->SetupAttachment(RootComponent);
OverlapSphere->SetSphereRadius(150.f);
OverlapSphere->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
OverlapSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
OverlapSphere->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
2022-05-22 20:56:28 +00:00
OverlapSphere->AddLocalOffset(FVector(0.f, 0.f, 85.f));
2022-05-22 15:04:10 +00:00
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
PickupMesh->SetupAttachment(OverlapSphere);
PickupMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
2022-05-22 20:56:28 +00:00
PickupMesh->SetRelativeScale3D(FVector(5.f, 5.f, 5.f));
PickupMesh->SetRenderCustomDepth(true);
PickupMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_PURPLE);
2022-05-22 15:04:10 +00:00
}
void APickup::BeginPlay()
{
Super::BeginPlay();
if (HasAuthority())
{
OverlapSphere->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnSphereOverlap);
}
}
void APickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& SweepResult)
{
2022-05-22 20:56:28 +00:00
UE_LOG(LogTemp, Warning, TEXT("Pickup Overlap"));
2022-05-22 15:04:10 +00:00
}
void APickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
2022-05-22 20:56:28 +00:00
if (PickupMesh)
{
PickupMesh->AddWorldRotation(FRotator(0.f, BaseTurnRate * DeltaTime, 0.f));
}
2022-05-22 15:04:10 +00:00
}
void APickup::Destroyed()
{
Super::Destroyed();
if (PickupSound)
{
UGameplayStatics::PlaySoundAtLocation(
this,
PickupSound,
GetActorLocation()
);
}
}