Create ThrowThrowable method

This commit is contained in:
baz 2023-09-08 22:17:05 +01:00
parent 1023a4f2b7
commit 42f99410e0
4 changed files with 23 additions and 7 deletions

View File

@ -13,6 +13,7 @@
#include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/CharacterMovementComponent.h"
#include "InputMappingContext.h" #include "InputMappingContext.h"
#include "EnemyCharacter.h" #include "EnemyCharacter.h"
#include "Throwable.h"
#define COLLISION_WEAPON ECC_GameTraceChannel1 #define COLLISION_WEAPON ECC_GameTraceChannel1
@ -561,3 +562,17 @@ float APlayerCharacter::GetWeaponSpread()
return CurrentWeapon->GetWeaponProperties()->WeaponSpread; return CurrentWeapon->GetWeaponProperties()->WeaponSpread;
} }
void APlayerCharacter::ThrowThrowable()
{
FVector Location;
FVector BoxExtent;
GetActorBounds(true, Location, BoxExtent, false);
FVector SpawnLocation = FVector(Location.Z, Location.Y + (BoxExtent.Y / 2), Location.Z + (BoxExtent.Z / 2));
AThrowable* Throwable = GetWorld()->SpawnActor<AThrowable>(SpawnLocation, FRotator::ZeroRotator);
// TODO: Set the collision size to the size of the static mesh in the throwable
//throwable->GetSphereComponent()->SetSphereRadius();
}

View File

@ -175,6 +175,8 @@ public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
float GetWeaponSpread(); float GetWeaponSpread();
void ThrowThrowable();
protected: protected:
virtual void CalculateHits(TArray<FHitResult>* hits) override; virtual void CalculateHits(TArray<FHitResult>* hits) override;

View File

@ -9,7 +9,7 @@
// Sets default values // Sets default values
AThrowable::AThrowable() AThrowable::AThrowable()
{ {
// 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 = false; PrimaryActorTick.bCanEverTick = false;
StaticMeshComponent->SetCollisionProfileName(FName("NoCollision")); StaticMeshComponent->SetCollisionProfileName(FName("NoCollision"));
@ -19,9 +19,6 @@ AThrowable::AThrowable()
SphereComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndProbe); SphereComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndProbe);
SphereComponent->SetCollisionProfileName(FName("IgnoreOnlyPawn")); SphereComponent->SetCollisionProfileName(FName("IgnoreOnlyPawn"));
SphereComponent->SetupAttachment(RootComponent); SphereComponent->SetupAttachment(RootComponent);
HealthComponent->OnDeath.BindUFunction(this, "Explode");
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
@ -30,7 +27,7 @@ void AThrowable::BeginPlay()
Super::BeginPlay(); Super::BeginPlay();
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AThrowable::OnOverlapBegin); SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AThrowable::OnOverlapBegin);
auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(),0)); auto playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
auto playerForwardVector = playerCharacter->GetActorForwardVector(); auto playerForwardVector = playerCharacter->GetActorForwardVector();
StaticMeshComponent->AddImpulse(playerForwardVector); StaticMeshComponent->AddImpulse(playerForwardVector);
} }

View File

@ -31,4 +31,6 @@ public:
UPrimitiveComponent* OtherComp, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
USphereComponent* GetSphereComponent() const { return SphereComponent; }
}; };