Create ThrowThrowable method
This commit is contained in:
parent
1023a4f2b7
commit
42f99410e0
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -175,6 +175,8 @@ public:
|
|||
UFUNCTION(BlueprintCallable)
|
||||
float GetWeaponSpread();
|
||||
|
||||
void ThrowThrowable();
|
||||
|
||||
protected:
|
||||
virtual void CalculateHits(TArray<FHitResult>* hits) override;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// Sets default values
|
||||
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;
|
||||
|
||||
StaticMeshComponent->SetCollisionProfileName(FName("NoCollision"));
|
||||
|
@ -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
|
||||
|
@ -30,7 +27,7 @@ void AThrowable::BeginPlay()
|
|||
Super::BeginPlay();
|
||||
|
||||
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();
|
||||
StaticMeshComponent->AddImpulse(playerForwardVector);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ private:
|
|||
|
||||
UPROPERTY()
|
||||
USphereComponent* SphereComponent;
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
AThrowable();
|
||||
|
||||
|
@ -31,4 +31,6 @@ public:
|
|||
UPrimitiveComponent* OtherComp,
|
||||
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
|
||||
USphereComponent* GetSphereComponent() const { return SphereComponent; }
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue