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 "InputMappingContext.h"
#include "EnemyCharacter.h"
#include "Throwable.h"
#define COLLISION_WEAPON ECC_GameTraceChannel1
@ -561,3 +562,17 @@ float APlayerCharacter::GetWeaponSpread()
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)
float GetWeaponSpread();
void ThrowThrowable();
protected:
virtual void CalculateHits(TArray<FHitResult>* hits) override;

View File

@ -19,9 +19,6 @@ AThrowable::AThrowable()
SphereComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndProbe);
SphereComponent->SetCollisionProfileName(FName("IgnoreOnlyPawn"));
SphereComponent->SetupAttachment(RootComponent);
HealthComponent->OnDeath.BindUFunction(this, "Explode");
}
// Called when the game starts or when spawned

View File

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