Add Knife Weapon
This commit is contained in:
parent
b8f08e83cc
commit
d9dba81c7e
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
Loading…
Reference in New Issue