diff --git a/Content/Weapons/BP_ExampleWeapon.uasset b/Content/Weapons/BP_ExampleWeapon.uasset new file mode 100644 index 0000000..92dda7b --- /dev/null +++ b/Content/Weapons/BP_ExampleWeapon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28701ef93e62244d2ff09ec921709ada9a8f58e15a687efb29a85a373fede1dc +size 26156 diff --git a/Content/Weapons/Knife/BP_KnifeWeapon.uasset b/Content/Weapons/Knife/BP_KnifeWeapon.uasset new file mode 100644 index 0000000..0688269 --- /dev/null +++ b/Content/Weapons/Knife/BP_KnifeWeapon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4bc215712fb409b6ce7212c817b472cc7d67d09c215717e9fe56275811b69f77 +size 23904 diff --git a/Source/vampires/PlayerCharacter.cpp b/Source/vampires/PlayerCharacter.cpp index 0c3fe87..f09b1b2 100644 --- a/Source/vampires/PlayerCharacter.cpp +++ b/Source/vampires/PlayerCharacter.cpp @@ -79,11 +79,11 @@ UGoldComponent* APlayerCharacter::GetGoldComponent() void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance) { - FVector2D vec2 = Instance.GetValue().Get(); + PreviousMovementDirection = Instance.GetValue().Get(); - if (vec2.Size() != 0.0f) + if (PreviousMovementDirection.Size() != 0.0f) { - AddMovementInput({0.0f, 1.0f, 0.0f}, vec2.Y); - AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X); + AddMovementInput({0.0f, 1.0f, 0.0f}, PreviousMovementDirection.Y); + AddMovementInput({1.0f, 0.0f, 0.0f}, PreviousMovementDirection.X); } } diff --git a/Source/vampires/PlayerCharacter.h b/Source/vampires/PlayerCharacter.h index 723d018..4604d8d 100644 --- a/Source/vampires/PlayerCharacter.h +++ b/Source/vampires/PlayerCharacter.h @@ -44,6 +44,8 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite) UWeaponInventoryComponent* WeaponInventoryComponent; + FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f); + private: FTimerHandle GarlicTimerHandle; diff --git a/Source/vampires/Weapons/FireWandWeapon.cpp b/Source/vampires/Weapons/FireWandWeapon.cpp index fb4f73b..3bd6897 100644 --- a/Source/vampires/Weapons/FireWandWeapon.cpp +++ b/Source/vampires/Weapons/FireWandWeapon.cpp @@ -16,6 +16,8 @@ void AFireWandWeapon::BeginPlay() void AFireWandWeapon::FireWeaponAction_Implementation() { + Super::FireWeaponAction_Implementation(); + if (IsValid(ProjectileTemplate) && OverlappedEnemies.Num() > 0) { FActorSpawnParameters actorSpawnParameters; diff --git a/Source/vampires/Weapons/KnifeWeapon.cpp b/Source/vampires/Weapons/KnifeWeapon.cpp new file mode 100644 index 0000000..dcf4947 --- /dev/null +++ b/Source/vampires/Weapons/KnifeWeapon.cpp @@ -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(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(ProjectileTemplate, GetOwner()->GetTransform(), + actorSpawnParameters); + + FVector direction = FVector(playerCharacter->PreviousMovementDirection, 0.0); + direction.Normalize(); + projectile->TargetDirection = direction; + } +} diff --git a/Source/vampires/Weapons/KnifeWeapon.h b/Source/vampires/Weapons/KnifeWeapon.h new file mode 100644 index 0000000..086042d --- /dev/null +++ b/Source/vampires/Weapons/KnifeWeapon.h @@ -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; +};