feat: 更新移动系统

This commit is contained in:
meishibiezb
2026-03-15 00:56:36 +08:00
parent b2cb9a4d0c
commit abc7730d94
53 changed files with 3974 additions and 12 deletions

View File

@@ -1,15 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyCharacter.h"
#include "EnhancedInputSubsystems.h"
#include "EnhancedInputComponent.h"
#include "MyCharacter.h"
void AMyCharacter::Move(const FInputActionValue& Value)
{
auto f2d = Value.Get<FVector2D>();
AddMovementInput(GetActorRotation().Vector());
auto f = GetActorForwardVector();
auto r = GetActorRightVector();
AddMovementInput(f * f2d.X);
AddMovementInput(r * f2d.Y);
}
void AMyCharacter::BeginRun(const FInputActionValue& Value)
{
bIsRunning = true;
}
void AMyCharacter::StopRun(const FInputActionValue& Value)
{
bIsRunning = false;
}
// Sets default values
@@ -40,7 +52,7 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone
Super::SetupPlayerInputComponent(PlayerInputComponent);
auto PlayerController = Cast<APlayerController>(GetController());
UEnhancedInputLocalPlayerSubsystem* Subsystem;
UEnhancedInputLocalPlayerSubsystem* Subsystem = NULL;
if (PlayerController)
{
Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer());

View File

@@ -16,9 +16,15 @@ public:
class UInputMappingContext* DefaultMapping;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
class UInputAction* MoveAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
class UInputAction* RunAction;
UFUNCTION(BlueprintCallable, Category = "Move")
void Move(const FInputActionValue& Value);
UFUNCTION(BlueprintCallable, Category = "Move")
void BeginRun(const FInputActionValue& Value);
UFUNCTION(BlueprintCallable, Category = "Move")
void StopRun(const FInputActionValue& Value);
// Sets default values for this character's properties
AMyCharacter();
@@ -32,6 +38,6 @@ protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
private:
private:
bool bIsRunning = false;
};