Add Knife Weapon

This commit is contained in:
baz 2024-07-31 15:04:31 +01:00
parent b8f08e83cc
commit d9dba81c7e
7 changed files with 76 additions and 4 deletions

BIN
Content/Weapons/BP_ExampleWeapon.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Weapons/Knife/BP_KnifeWeapon.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -79,11 +79,11 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance) void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
{ {
FVector2D vec2 = Instance.GetValue().Get<FVector2D>(); PreviousMovementDirection = Instance.GetValue().Get<FVector2D>();
if (vec2.Size() != 0.0f) if (PreviousMovementDirection.Size() != 0.0f)
{ {
AddMovementInput({0.0f, 1.0f, 0.0f}, vec2.Y); AddMovementInput({0.0f, 1.0f, 0.0f}, PreviousMovementDirection.Y);
AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X); AddMovementInput({1.0f, 0.0f, 0.0f}, PreviousMovementDirection.X);
} }
} }

View File

@ -44,6 +44,8 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
UWeaponInventoryComponent* WeaponInventoryComponent; UWeaponInventoryComponent* WeaponInventoryComponent;
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
private: private:
FTimerHandle GarlicTimerHandle; FTimerHandle GarlicTimerHandle;

View File

@ -16,6 +16,8 @@ void AFireWandWeapon::BeginPlay()
void AFireWandWeapon::FireWeaponAction_Implementation() void AFireWandWeapon::FireWeaponAction_Implementation()
{ {
Super::FireWeaponAction_Implementation();
if (IsValid(ProjectileTemplate) && OverlappedEnemies.Num() > 0) if (IsValid(ProjectileTemplate) && OverlappedEnemies.Num() > 0)
{ {
FActorSpawnParameters actorSpawnParameters; FActorSpawnParameters actorSpawnParameters;

View File

@ -0,0 +1,37 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "KnifeWeapon.h"
#include "Kismet/GameplayStatics.h"
#include "vampires/PlayerCharacter.h"
AKnifeWeapon::AKnifeWeapon()
{
}
void AKnifeWeapon::BeginPlay()
{
Super::BeginPlay();
}
void AKnifeWeapon::FireWeaponAction_Implementation()
{
Super::FireWeaponAction_Implementation();
APlayerCharacter* playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
if (IsValid(ProjectileTemplate) && playerCharacter)
{
FActorSpawnParameters actorSpawnParameters;
actorSpawnParameters.Owner = this;
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
actorSpawnParameters);
FVector direction = FVector(playerCharacter->PreviousMovementDirection, 0.0);
direction.Normalize();
projectile->TargetDirection = direction;
}
}

View File

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "ProjectileWeapon.h"
#include "KnifeWeapon.generated.h"
/**
*
*/
UCLASS()
class VAMPIRES_API AKnifeWeapon : public AProjectileWeapon
{
GENERATED_BODY()
public:
AKnifeWeapon();
protected:
virtual void BeginPlay() override;
public:
virtual void FireWeaponAction_Implementation() override;
};