Make gun weapon fire to the corner of the screen rather than diagonally
This commit is contained in:
parent
64dc8ec7d1
commit
850ebb973e
|
@ -3,6 +3,11 @@
|
||||||
|
|
||||||
#include "GunWeapon.h"
|
#include "GunWeapon.h"
|
||||||
|
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
|
#include "vampires/PlayerCharacter.h"
|
||||||
|
#include "vampires/VampirePlayerController.h"
|
||||||
|
|
||||||
AGunWeapon::AGunWeapon()
|
AGunWeapon::AGunWeapon()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -18,25 +23,48 @@ void AGunWeapon::FireWeaponAction_Implementation()
|
||||||
|
|
||||||
if (IsValid(ProjectileTemplate))
|
if (IsValid(ProjectileTemplate))
|
||||||
{
|
{
|
||||||
|
FVector2d ViewportSize;
|
||||||
|
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||||
|
|
||||||
|
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||||
|
AVampirePlayerController* PlayerController = Cast<AVampirePlayerController>(
|
||||||
|
UGameplayStatics::GetPlayerController(PlayerCharacter, 0));
|
||||||
|
|
||||||
|
FVector TopLeft, TopLeftDir;
|
||||||
|
FVector TopRight, TopRightDir;
|
||||||
|
FVector BottomLeft, BottomLeftDir;
|
||||||
|
FVector BottomRight, BottomRightDir;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
FVector actorLocation = GetActorLocation();
|
||||||
|
TopLeft.Z = actorLocation.Z;
|
||||||
|
TopRight.Z = actorLocation.Z;
|
||||||
|
BottomLeft.Z = actorLocation.Z;
|
||||||
|
BottomRight.Z = actorLocation.Z;
|
||||||
|
|
||||||
FActorSpawnParameters actorSpawnParameters;
|
FActorSpawnParameters actorSpawnParameters;
|
||||||
actorSpawnParameters.Owner = this;
|
actorSpawnParameters.Owner = this;
|
||||||
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
|
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
|
||||||
|
|
||||||
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||||
actorSpawnParameters);
|
actorSpawnParameters);
|
||||||
projectile->TargetDirection = FVector(1.0f, 1.0f, 0.0f);
|
projectile->TargetDirection = UKismetMathLibrary::GetDirectionUnitVector(actorLocation, TopLeft);
|
||||||
|
|
||||||
projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||||
actorSpawnParameters);
|
actorSpawnParameters);
|
||||||
projectile->TargetDirection = FVector(-1.0f, 1.0f, 0.0f);
|
projectile->TargetDirection = UKismetMathLibrary::GetDirectionUnitVector(actorLocation, TopRight);
|
||||||
|
|
||||||
projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||||
actorSpawnParameters);
|
actorSpawnParameters);
|
||||||
projectile->TargetDirection = FVector(1.0f, -1.0f, 0.0f);
|
projectile->TargetDirection = UKismetMathLibrary::GetDirectionUnitVector(actorLocation, BottomLeft);
|
||||||
|
|
||||||
projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||||
actorSpawnParameters);
|
actorSpawnParameters);
|
||||||
projectile->TargetDirection = FVector(-1.0f, -1.0f, 0.0f);
|
projectile->TargetDirection = UKismetMathLibrary::GetDirectionUnitVector(actorLocation, BottomRight);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue