Switch Projectile weapons to Box Collider instead of Sphere Component
This commit is contained in:
parent
410dd9caf7
commit
64dc8ec7d1
|
@ -31,6 +31,7 @@ void APentagramWeapon::BeginPlay()
|
||||||
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||||
AVampirePlayerController* PlayerController = Cast<AVampirePlayerController>(
|
AVampirePlayerController* PlayerController = Cast<AVampirePlayerController>(
|
||||||
UGameplayStatics::GetPlayerController(PlayerCharacter, 0));
|
UGameplayStatics::GetPlayerController(PlayerCharacter, 0));
|
||||||
|
|
||||||
PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir);
|
PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir);
|
||||||
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, 0, TopRight, TopRightDir);
|
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, 0, TopRight, TopRightDir);
|
||||||
PlayerController->DeprojectScreenPositionToWorld(0, ViewportSize.Y, BottomLeft, BottomLeftDir);
|
PlayerController->DeprojectScreenPositionToWorld(0, ViewportSize.Y, BottomLeft, BottomLeftDir);
|
||||||
|
|
|
@ -3,20 +3,43 @@
|
||||||
|
|
||||||
#include "ProjectileWeapon.h"
|
#include "ProjectileWeapon.h"
|
||||||
|
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
#include "vampires/EnemyCharacter.h"
|
#include "vampires/EnemyCharacter.h"
|
||||||
|
#include "vampires/PlayerCharacter.h"
|
||||||
|
#include "vampires/VampirePlayerController.h"
|
||||||
|
|
||||||
AProjectileWeapon::AProjectileWeapon()
|
AProjectileWeapon::AProjectileWeapon()
|
||||||
{
|
{
|
||||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Box Component"));
|
||||||
SphereComponent->SetupAttachment(RootComponent);
|
BoxComponent->SetupAttachment(RootComponent);
|
||||||
SphereComponent->SetSphereRadius(1000.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AProjectileWeapon::BeginPlay()
|
void AProjectileWeapon::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AProjectileWeapon::OnWeaponBeginOverlap);
|
BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &AProjectileWeapon::OnWeaponBeginOverlap);
|
||||||
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AProjectileWeapon::OnWeaponEndOverlap);
|
BoxComponent->OnComponentEndOverlap.AddDynamic(this, &AProjectileWeapon::OnWeaponEndOverlap);
|
||||||
|
|
||||||
|
FVector TopLeft, TopLeftDir;
|
||||||
|
FVector TopRight, TopRightDir;
|
||||||
|
FVector BottomLeft, BottomLeftDir;
|
||||||
|
FVector BottomRight, BottomRightDir;
|
||||||
|
|
||||||
|
FVector2d ViewportSize;
|
||||||
|
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||||
|
|
||||||
|
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||||
|
AVampirePlayerController* PlayerController = Cast<AVampirePlayerController>(
|
||||||
|
UGameplayStatics::GetPlayerController(PlayerCharacter, 0));
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
float width = FVector::Dist(TopLeft, TopRight) * 60;
|
||||||
|
float height = FVector::Dist(TopLeft, BottomLeft) * 60;
|
||||||
|
BoxComponent->SetBoxExtent(FVector(height, width, 200.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AProjectileWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
void AProjectileWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "../Weapon.h"
|
#include "../Weapon.h"
|
||||||
|
#include "Components/BoxComponent.h"
|
||||||
#include "vampires/Projectile.h"
|
#include "vampires/Projectile.h"
|
||||||
#include "ProjectileWeapon.generated.h"
|
#include "ProjectileWeapon.generated.h"
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ class VAMPIRES_API AProjectileWeapon : public AWeapon
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
public:
|
public:
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
USphereComponent* SphereComponent = nullptr;
|
UBoxComponent* BoxComponent = nullptr;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
|
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
|
||||||
TSubclassOf<AProjectile> ProjectileTemplate = nullptr;
|
TSubclassOf<AProjectile> ProjectileTemplate = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue