Get Previous Movement Direction using Inputable interface

This commit is contained in:
baz 2024-11-22 00:29:50 +00:00
parent dc5e4bb3a2
commit e07abfbcfc
5 changed files with 29 additions and 15 deletions

View File

@ -27,4 +27,7 @@ public:
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
UInputMappingContext* Input_GetInputMappingContext();
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
FVector2D Input_GetPreviousMovementDirection();
};

View File

@ -37,8 +37,6 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UGoldComponent* GoldComponent;
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
UPROPERTY(EditAnywhere)
UWidgetComponent* HealthBarWidgetComponent;

View File

@ -41,6 +41,8 @@ void AVampireCharacter::Tick(float DeltaTime)
void AVampireCharacter::Input_Move_Implementation(FVector2D value)
{
PreviousMovementDirection = value;
if (value.Size() != 0.0f)
{
AddMovementInput({0.0f, 1.0f, 0.0f}, value.Y);
@ -53,6 +55,11 @@ UInputMappingContext* AVampireCharacter::Input_GetInputMappingContext_Implementa
return InputMappingContext;
}
FVector2D AVampireCharacter::Input_GetPreviousMovementDirection_Implementation()
{
return PreviousMovementDirection;
}
UHealthComponent* AVampireCharacter::GetHealthComponent()
{
return HealthComponent;

View File

@ -21,6 +21,8 @@ public:
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UPaperFlipbookComponent* PaperFlipbookComponent;
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
protected:
UPROPERTY()
UHealthComponent* HealthComponent;
@ -47,5 +49,7 @@ public:
virtual UInputMappingContext* Input_GetInputMappingContext_Implementation() override;
virtual FVector2D Input_GetPreviousMovementDirection_Implementation() override;
UHealthComponent* GetHealthComponent();
};

View File

@ -20,8 +20,9 @@ void AKnifeWeapon::FireWeaponAction_Implementation()
{
Super::FireWeaponAction_Implementation();
APlayerCharacter* playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
if (IsValid(ProjectileTemplate) && playerCharacter)
if (UKismetSystemLibrary::DoesImplementInterface(GetOwner(), UInputable::StaticClass()))
{
if (IsValid(ProjectileTemplate))
{
FActorSpawnParameters actorSpawnParameters;
actorSpawnParameters.Owner = this;
@ -31,8 +32,9 @@ void AKnifeWeapon::FireWeaponAction_Implementation()
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
actorSpawnParameters);
FVector direction = FVector(playerCharacter->PreviousMovementDirection, 0.0);
FVector direction = FVector(IInputable::Execute_Input_GetPreviousMovementDirection(GetOwner()), 0.0);
direction.Normalize();
projectile->SetTargetDirection(direction);
}
}
}