Compare commits
2 Commits
03023ed494
...
2e59bb6e0e
Author | SHA1 | Date |
---|---|---|
baz | 2e59bb6e0e | |
baz | a4d66dc45d |
BIN
Content/Gamemode/BP_DefaultGamemode.uasset (Stored with Git LFS)
BIN
Content/Gamemode/BP_DefaultGamemode.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -37,7 +37,6 @@ void APickup::Tick(float DeltaSeconds)
|
||||||
if (currentDistance <= PickupMovementRange)
|
if (currentDistance <= PickupMovementRange)
|
||||||
{
|
{
|
||||||
double speed = 400 / currentDistance;
|
double speed = 400 / currentDistance;
|
||||||
UE_LOG(LogTemp, Warning, TEXT("The integer value is: %f"), speed);
|
|
||||||
FVector location = FMath::VInterpTo(actorLocation, playerLocation, DeltaSeconds, speed);
|
FVector location = FMath::VInterpTo(actorLocation, playerLocation, DeltaSeconds, speed);
|
||||||
SetActorLocation(location);
|
SetActorLocation(location);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,3 +3,62 @@
|
||||||
|
|
||||||
#include "VampireGameMode.h"
|
#include "VampireGameMode.h"
|
||||||
|
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
void AVampireGameMode::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||||
|
PlayerController = Cast<AVampirePlayerController>(UGameplayStatics::GetPlayerController(PlayerCharacter, 0));
|
||||||
|
|
||||||
|
GetWorldTimerManager().SetTimer(SpawnEnemyTimerDelegate, this, &AVampireGameMode::SpawnEnemy, 1.0f, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVampireGameMode::SpawnEnemy()
|
||||||
|
{
|
||||||
|
FVector TopLeft, TopLeftDir;
|
||||||
|
FVector TopRight, TopRightDir;
|
||||||
|
FVector BottomLeft, BottomLeftDir;
|
||||||
|
FVector BottomRight, BottomRightDir;
|
||||||
|
FVector CenterPos, CenterDir;
|
||||||
|
|
||||||
|
FVector2d ViewportSize;
|
||||||
|
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||||
|
|
||||||
|
PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir);
|
||||||
|
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, 0, TopRight, TopRightDir);
|
||||||
|
PlayerController->DeprojectScreenPositionToWorld(0, ViewportSize.Y, BottomLeft, BottomLeftDir);
|
||||||
|
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight, BottomRightDir);
|
||||||
|
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X / 2, ViewportSize.Y / 2, CenterPos, CenterDir);
|
||||||
|
|
||||||
|
FVector SpawnLocation;
|
||||||
|
switch (FMath::RandRange(0, 3))
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
SpawnLocation = FMath::Lerp(TopLeft, TopRight, FMath::RandRange(0.0f, 1.0f));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
SpawnLocation = FMath::Lerp(TopRight, BottomRight, FMath::RandRange(0.0f, 1.0f));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
SpawnLocation = FMath::Lerp(BottomRight, BottomLeft, FMath::RandRange(0.0f, 1.0f));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
SpawnLocation = FMath::Lerp(BottomLeft, TopLeft, FMath::RandRange(0.0f, 1.0f));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("Something broke"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpawnLocation.Z = PlayerCharacter->GetActorLocation().Z;
|
||||||
|
FTransform Transform;
|
||||||
|
Transform.SetLocation(SpawnLocation);
|
||||||
|
|
||||||
|
FActorSpawnParameters SpawnParameters;
|
||||||
|
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
|
|
||||||
|
AEnemyCharacter* actor = GetWorld()->SpawnActor<AEnemyCharacter>(EnemyTemplate, Transform, SpawnParameters);
|
||||||
|
actor->SpawnDefaultController();
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "EnemyCharacter.h"
|
||||||
|
#include "PlayerCharacter.h"
|
||||||
|
#include "VampirePlayerController.h"
|
||||||
#include "GameFramework/GameMode.h"
|
#include "GameFramework/GameMode.h"
|
||||||
#include "VampireGameMode.generated.h"
|
#include "VampireGameMode.generated.h"
|
||||||
|
|
||||||
|
@ -14,4 +17,20 @@ class VAMPIRES_API AVampireGameMode : public AGameMode
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TSubclassOf<AEnemyCharacter> EnemyTemplate;
|
||||||
|
|
||||||
|
private:
|
||||||
|
APlayerCharacter* PlayerCharacter;
|
||||||
|
|
||||||
|
AVampirePlayerController* PlayerController;
|
||||||
|
|
||||||
|
FTimerHandle SpawnEnemyTimerDelegate;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void SpawnEnemy();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue