Compare commits
No commits in common. "e8d7c49a4e29d846443c49d0a90fa5ab84d9063f" and "9b0cfbecc359f03134c0bfb493072c1c515320e4" have entirely different histories.
e8d7c49a4e
...
9b0cfbecc3
|
@ -4,14 +4,13 @@
|
||||||
#include "Pickup.h"
|
#include "Pickup.h"
|
||||||
|
|
||||||
#include "PlayerCharacter.h"
|
#include "PlayerCharacter.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
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"));
|
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
||||||
SphereComponent->SetupAttachment(RootComponent);
|
SphereComponent->SetupAttachment(RootComponent);
|
||||||
|
@ -30,22 +29,10 @@ void APickup::Tick(float DeltaSeconds)
|
||||||
Super::Tick(DeltaSeconds);
|
Super::Tick(DeltaSeconds);
|
||||||
|
|
||||||
// TODO: Move actor towards player when in range
|
// 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;
|
|
||||||
UE_LOG(LogTemp, Warning, TEXT("The integer value is: %f"), speed);
|
|
||||||
FVector location = FMath::VInterpTo(actorLocation, playerLocation, DeltaSeconds, speed);
|
|
||||||
SetActorLocation(location);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
void APickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||||
const FHitResult& SweepResult)
|
|
||||||
{
|
{
|
||||||
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
||||||
{
|
{
|
||||||
|
@ -53,3 +40,4 @@ void APickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* O
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,6 @@ class VAMPIRES_API APickup : public AActor
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
|
||||||
double PickupMovementRange = 500;
|
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
|
||||||
double PickupMovementSpeed = 1000;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
USphereComponent* SphereComponent;
|
USphereComponent* SphereComponent;
|
||||||
|
@ -35,7 +27,6 @@ protected:
|
||||||
public:
|
public:
|
||||||
virtual void Tick(float DeltaSeconds) override;
|
virtual void Tick(float DeltaSeconds) override;
|
||||||
|
|
||||||
UFUNCTION()
|
|
||||||
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
const FHitResult& SweepResult);
|
const FHitResult& SweepResult);
|
||||||
|
|
Loading…
Reference in New Issue