UE5--007--Move和Jump(Input)
1. MyThirdPersonChar蓝图
1.1 MyThirdPersonChar.h
// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Camera/CameraComponent.h" #include "GameFramework/SpringArmComponent.h" #include "GameFramework/Character.h" #include "MyThirdPersonChar.generated.h" UCLASS() class C002MYBLANKPROJ_API AMyThirdPersonChar : public ACharacter { GENERATED_BODY() // Arm for Camera UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = MyTPS_Cam, meta = (AllowPrivateAccess = "true")) class USpringArmComponent* CameraBoom; // Follow camera UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = MyTPS_Cam, meta = (AllowPrivateAccess = "true")) class UCameraComponent* FollowCamera; public: // Sets default values for this character's properties AMyThirdPersonChar(); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; public: // Called every frame virtual void Tick(float DeltaTime) override; // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; };
1.2 MyThirdPersonChar.cpp
// Fill out your copyright notice in the Description page of Project Settings. #include "MyThirdPersonChar.h" #include "Components/CapsuleComponent.h" #include "GameFramework/CharacterMovementComponent.h" // Sets default values AMyThirdPersonChar::AMyThirdPersonChar() { // 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; // // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // Don't rotate when the controller rotates. Let that just affect the camera. bUseControllerRotationPitch = false; bUseControllerRotationYaw = false; bUseControllerRotationRoll = false; // Configure character movement GetCharacterMovement()->bOrientRotationToMovement = true; // Create a camera boom (pulls in towards the player if there is a collision) CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); CameraBoom->SetupAttachment(RootComponent); CameraBoom->TargetArmLength = 300.0f; CameraBoom->bUsePawnControlRotation = true; // Create a camera that will follow the character FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera")); FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); FollowCamera->bUsePawnControlRotation = false; } // Called when the game starts or when spawned void AMyThirdPersonChar::BeginPlay() { Super::BeginPlay(); } // Called every frame void AMyThirdPersonChar::Tick(float DeltaTime) { Super::Tick(DeltaTime); } // Called to bind functionality to input void AMyThirdPersonChar::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); }
2. Engine Input
3. BP_MyTPC蓝图(继承MyThirdPersonChar蓝图)


浙公网安备 33010602011771号