Use timeline for updating pickup position
This commit is contained in:
parent
ee0a537621
commit
18702cea0c
Binary file not shown.
BIN
Content/Pickups/EXP/BP_BlueEXPPickup.uasset (Stored with Git LFS)
BIN
Content/Pickups/EXP/BP_BlueEXPPickup.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/Pickups/EXP/BP_GreenEXPPickup.uasset (Stored with Git LFS)
BIN
Content/Pickups/EXP/BP_GreenEXPPickup.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/Pickups/EXP/BP_RedEXPPickup.uasset (Stored with Git LFS)
BIN
Content/Pickups/EXP/BP_RedEXPPickup.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/Pickups/Gold/BP_GoldPickup.uasset (Stored with Git LFS)
BIN
Content/Pickups/Gold/BP_GoldPickup.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -16,12 +16,12 @@ void AEXPPickup::Tick(float DeltaSeconds)
|
||||||
Super::Tick(DeltaSeconds);
|
Super::Tick(DeltaSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AEXPPickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
void AEXPPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||||
{
|
{
|
||||||
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
||||||
{
|
{
|
||||||
PlayerCharacter->GetEXPComponent()->IncrementEXP(EXP);
|
PlayerCharacter->GetEXPComponent()->IncrementEXP(EXP);
|
||||||
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
virtual void Tick(float DeltaSeconds) override;
|
virtual void Tick(float DeltaSeconds) override;
|
||||||
|
|
||||||
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
const FHitResult& SweepResult) override;
|
const FHitResult& SweepResult) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,12 +18,12 @@ void AGoldPickup::Tick(float DeltaSeconds)
|
||||||
Super::Tick(DeltaSeconds);
|
Super::Tick(DeltaSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AGoldPickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
void AGoldPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||||
{
|
{
|
||||||
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
||||||
{
|
{
|
||||||
PlayerCharacter->GetGoldComponent()->IncrementGold(Gold);
|
PlayerCharacter->GetGoldComponent()->IncrementGold(Gold);
|
||||||
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
virtual void Tick(float DeltaSeconds) override;
|
virtual void Tick(float DeltaSeconds) override;
|
||||||
|
|
||||||
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
const FHitResult& SweepResult) override;
|
const FHitResult& SweepResult) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "Pickup.h"
|
#include "Pickup.h"
|
||||||
|
|
||||||
#include "PlayerCharacter.h"
|
#include "PlayerCharacter.h"
|
||||||
#include "Components/SphereComponent.h"
|
#include "Components/SphereComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
@ -12,44 +11,50 @@
|
||||||
APickup::APickup()
|
APickup::APickup()
|
||||||
{
|
{
|
||||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||||
PrimaryActorTick.bCanEverTick = true;
|
PrimaryActorTick.bCanEverTick = false;
|
||||||
|
|
||||||
// Create Sphere Component
|
// Create Sphere Component
|
||||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
InnerSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Inner Sphere Component"));
|
||||||
SetRootComponent(SphereComponent);
|
SetRootComponent(InnerSphereComponent);
|
||||||
SphereComponent->SetSphereRadius(25.0f);
|
InnerSphereComponent->SetSphereRadius(25.0f);
|
||||||
|
|
||||||
|
OuterSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Outer Sphere Component"));
|
||||||
|
OuterSphereComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
|
||||||
|
OuterSphereComponent->SetSphereRadius(250.0f);
|
||||||
|
|
||||||
SpriteComponent = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("Sprite Component"));
|
SpriteComponent = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("Sprite Component"));
|
||||||
SpriteComponent->SetRelativeRotation(FRotator(0.0f, 90.0f, -90.0f));
|
SpriteComponent->SetRelativeRotation(FRotator(0.0f, 90.0f, -90.0f));
|
||||||
SpriteComponent->SetRelativeScale3D(FVector(.5f, .5f, .5f));
|
SpriteComponent->SetRelativeScale3D(FVector(.5f, .5f, .5f));
|
||||||
|
SpriteComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||||
SpriteComponent->SetupAttachment(RootComponent);
|
SpriteComponent->SetupAttachment(RootComponent);
|
||||||
|
|
||||||
|
TimelineComponent = CreateDefaultSubobject<UTimelineComponent>(TEXT("Timeline Component"));
|
||||||
|
TimelineComponent->SetDirectionPropertyName(FName("TimelineDirection"));
|
||||||
|
TimelineComponent->SetLooping(false);
|
||||||
|
TimelineComponent->SetTimelineLength(5.0f);
|
||||||
|
TimelineComponent->SetTimelineLengthMode(TL_TimelineLength);
|
||||||
|
TimelineComponent->SetPlaybackPosition(0.0f, false);
|
||||||
|
|
||||||
|
onTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback")));
|
||||||
|
onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
void APickup::BeginPlay()
|
void APickup::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnBeginOverlap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void APickup::Tick(float DeltaSeconds)
|
InnerSphereComponent->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnInnerBeginOverlap);
|
||||||
|
OuterSphereComponent->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnOuterBeginOverlap);
|
||||||
|
|
||||||
|
if (CurveFloat != nullptr)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaSeconds);
|
TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback);
|
||||||
|
TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback);
|
||||||
// TODO: Move actor towards player when in range
|
|
||||||
FVector actorLocation = GetActorLocation();
|
|
||||||
FVector playerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation();
|
|
||||||
double currentDistance = FVector::Distance(actorLocation, playerLocation);
|
|
||||||
|
|
||||||
if (currentDistance <= PickupMovementRange)
|
|
||||||
{
|
|
||||||
double speed = 400 / currentDistance;
|
|
||||||
FVector location = FMath::VInterpTo(actorLocation, playerLocation, DeltaSeconds, speed);
|
|
||||||
SetActorLocation(location);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void APickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
void APickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
const FHitResult& SweepResult)
|
const FHitResult& SweepResult)
|
||||||
{
|
{
|
||||||
|
@ -64,3 +69,31 @@ void APickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* O
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void APickup::OnOuterBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
|
const FHitResult& SweepResult)
|
||||||
|
{
|
||||||
|
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
||||||
|
{
|
||||||
|
PickupLocation = GetActorLocation();
|
||||||
|
PlayTimeLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void APickup::TimelineCallback(float val)
|
||||||
|
{
|
||||||
|
FVector actorLocation = PickupLocation;
|
||||||
|
FVector playerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation();
|
||||||
|
FVector location = FMath::Lerp(actorLocation, playerLocation, val);
|
||||||
|
SetActorLocation(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
void APickup::TimelineFinishedCallback()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void APickup::PlayTimeLine()
|
||||||
|
{
|
||||||
|
TimelineComponent->Play();
|
||||||
|
}
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "Components/TimelineComponent.h"
|
||||||
#include "GameFramework/Actor.h"
|
#include "GameFramework/Actor.h"
|
||||||
#include "Pickup.generated.h"
|
#include "Pickup.generated.h"
|
||||||
|
|
||||||
|
class UTimelineComponent;
|
||||||
class USphereComponent;
|
class USphereComponent;
|
||||||
class UPaperSpriteComponent;
|
class UPaperSpriteComponent;
|
||||||
|
|
||||||
|
@ -23,7 +25,10 @@ public:
|
||||||
double PickupMovementSpeed = 1000;
|
double PickupMovementSpeed = 1000;
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
USphereComponent* SphereComponent = nullptr;
|
USphereComponent* InnerSphereComponent = nullptr;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
USphereComponent* OuterSphereComponent = nullptr;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
UPaperSpriteComponent* SpriteComponent = nullptr;
|
UPaperSpriteComponent* SpriteComponent = nullptr;
|
||||||
|
@ -31,6 +36,18 @@ public:
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
USoundBase* PickupSoundBase = nullptr;
|
USoundBase* PickupSoundBase = nullptr;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Timeline")
|
||||||
|
TObjectPtr<UTimelineComponent> TimelineComponent;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Timeline")
|
||||||
|
UCurveFloat* CurveFloat;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FOnTimelineFloat onTimelineCallback;
|
||||||
|
FOnTimelineEventStatic onTimelineFinishedCallback;
|
||||||
|
|
||||||
|
FVector PickupLocation;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
APickup();
|
APickup();
|
||||||
|
@ -39,11 +56,22 @@ protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
|
||||||
virtual void Tick(float DeltaSeconds) override;
|
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
const FHitResult& SweepResult);
|
const FHitResult& SweepResult);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
virtual void OnOuterBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
|
const FHitResult& SweepResult);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void TimelineCallback(float val);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void TimelineFinishedCallback();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void PlayTimeLine();
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,7 @@ APlayerCharacter::APlayerCharacter()
|
||||||
HealthBarWidgetComponent->SetRelativeLocation(FVector(0, 0, 90));
|
HealthBarWidgetComponent->SetRelativeLocation(FVector(0, 0, 90));
|
||||||
HealthBarWidgetComponent->SetTwoSided(true);
|
HealthBarWidgetComponent->SetTwoSided(true);
|
||||||
HealthBarWidgetComponent->SetBackgroundColor(FLinearColor(1, 1, 1, 0));
|
HealthBarWidgetComponent->SetBackgroundColor(FLinearColor(1, 1, 1, 0));
|
||||||
|
HealthBarWidgetComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::BeginPlay()
|
void APlayerCharacter::BeginPlay()
|
||||||
|
|
Loading…
Reference in New Issue