Get Previous Movement Direction using Inputable interface
This commit is contained in:
parent
dc5e4bb3a2
commit
e07abfbcfc
|
@ -27,4 +27,7 @@ public:
|
|||
|
||||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
|
||||
UInputMappingContext* Input_GetInputMappingContext();
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
|
||||
FVector2D Input_GetPreviousMovementDirection();
|
||||
};
|
||||
|
|
|
@ -37,8 +37,6 @@ public:
|
|||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UGoldComponent* GoldComponent;
|
||||
|
||||
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
UWidgetComponent* HealthBarWidgetComponent;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -21,13 +21,15 @@ public:
|
|||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
UPaperFlipbookComponent* PaperFlipbookComponent;
|
||||
|
||||
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
|
||||
|
||||
protected:
|
||||
UPROPERTY()
|
||||
UHealthComponent* HealthComponent;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UInputMappingContext> InputMappingContext;
|
||||
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UWeaponInventoryComponent* WeaponInventoryComponent;
|
||||
|
||||
|
@ -47,5 +49,7 @@ public:
|
|||
|
||||
virtual UInputMappingContext* Input_GetInputMappingContext_Implementation() override;
|
||||
|
||||
virtual FVector2D Input_GetPreviousMovementDirection_Implementation() override;
|
||||
|
||||
UHealthComponent* GetHealthComponent();
|
||||
};
|
||||
|
|
|
@ -20,19 +20,21 @@ 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()))
|
||||
{
|
||||
FActorSpawnParameters actorSpawnParameters;
|
||||
actorSpawnParameters.Owner = this;
|
||||
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
|
||||
if (IsValid(ProjectileTemplate))
|
||||
{
|
||||
FActorSpawnParameters actorSpawnParameters;
|
||||
actorSpawnParameters.Owner = this;
|
||||
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
|
||||
|
||||
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||
actorSpawnParameters);
|
||||
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(),
|
||||
actorSpawnParameters);
|
||||
|
||||
FVector direction = FVector(playerCharacter->PreviousMovementDirection, 0.0);
|
||||
direction.Normalize();
|
||||
projectile->SetTargetDirection(direction);
|
||||
}
|
||||
FVector direction = FVector(IInputable::Execute_Input_GetPreviousMovementDirection(GetOwner()), 0.0);
|
||||
direction.Normalize();
|
||||
projectile->SetTargetDirection(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue