feat: 增加蹲下功能
This commit is contained in:
Binary file not shown.
BIN
Content/Inputs/IA/IA_CrouchAction.uasset
LFS
Normal file
BIN
Content/Inputs/IA/IA_CrouchAction.uasset
LFS
Normal file
Binary file not shown.
Binary file not shown.
@@ -27,19 +27,36 @@ void AMyCharacter::StopRun(const FInputActionValue& Value)
|
|||||||
GetCharacterMovement()->MaxWalkSpeed = 600.0f;
|
GetCharacterMovement()->MaxWalkSpeed = 600.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AMyCharacter::BeginCrouch(const FInputActionValue& Value)
|
||||||
|
{
|
||||||
|
bIsCrouching = true;
|
||||||
|
GetCharacterMovement()->bWantsToCrouch = true;
|
||||||
|
GetCharacterMovement()->Crouch();
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("Crouching"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AMyCharacter::StopCrouch(const FInputActionValue& Value)
|
||||||
|
{
|
||||||
|
bIsCrouching = false;
|
||||||
|
GetCharacterMovement()->bWantsToCrouch = false;
|
||||||
|
GetCharacterMovement()->UnCrouch();
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("Stop Crouch"));
|
||||||
|
}
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
AMyCharacter::AMyCharacter()
|
AMyCharacter::AMyCharacter()
|
||||||
{
|
{
|
||||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||||
PrimaryActorTick.bCanEverTick = true;
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
|
||||||
|
GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
void AMyCharacter::BeginPlay()
|
void AMyCharacter::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
@@ -75,6 +92,10 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone
|
|||||||
EnhancedInputComponent->BindAction(RunAction, ETriggerEvent::Started, this, &AMyCharacter::BeginRun);
|
EnhancedInputComponent->BindAction(RunAction, ETriggerEvent::Started, this, &AMyCharacter::BeginRun);
|
||||||
EnhancedInputComponent->BindAction(RunAction, ETriggerEvent::Completed, this, &AMyCharacter::StopRun);
|
EnhancedInputComponent->BindAction(RunAction, ETriggerEvent::Completed, this, &AMyCharacter::StopRun);
|
||||||
}
|
}
|
||||||
|
if (CrouchAction) {
|
||||||
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AMyCharacter::BeginCrouch);
|
||||||
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AMyCharacter::StopCrouch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ public:
|
|||||||
class UInputAction* MoveAction;
|
class UInputAction* MoveAction;
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||||
class UInputAction* RunAction;
|
class UInputAction* RunAction;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||||
|
class UInputAction* CrouchAction;
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||||
void Move(const FInputActionValue& Value);
|
void Move(const FInputActionValue& Value);
|
||||||
@@ -25,6 +27,15 @@ public:
|
|||||||
void BeginRun(const FInputActionValue& Value);
|
void BeginRun(const FInputActionValue& Value);
|
||||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||||
void StopRun(const FInputActionValue& Value);
|
void StopRun(const FInputActionValue& Value);
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||||
|
void BeginCrouch(const FInputActionValue& Value);
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||||
|
void StopCrouch(const FInputActionValue& Value);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "State")
|
||||||
|
bool IsRunning() const { return bIsRunning; }
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "State")
|
||||||
|
bool IsCrouching() const { return bIsCrouching; }
|
||||||
|
|
||||||
// Sets default values for this character's properties
|
// Sets default values for this character's properties
|
||||||
AMyCharacter();
|
AMyCharacter();
|
||||||
@@ -40,4 +51,5 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool bIsRunning = false;
|
bool bIsRunning = false;
|
||||||
|
bool bIsCrouching = false;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user