I believe I implemented all the code needed for my Pawn to accept input and move. I have tried input with Keyboard/Mouse as well as Controller. Am I missing something?
MainPlayer.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BasePawn.h"
#include "MainPlayer.generated.h"
/**
*
*/
UCLASS()
class THIRDPERSONMOVEMENT_API AMainPlayer : public ABasePawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AMainPlayer();
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
private:
UPROPERTY(VisibleAnywhere, Category = "Components")
class USpringArmComponent* SpringArm;
UPROPERTY(VisibleAnywhere, Category = "Components")
class UCameraComponent* Camera;
UPROPERTY(EditAnywhere, Category = "Movement")
float RotationRate = 10.f;
void MoveForward(float AxisValue);
void MoveRight(float AxisValue);
void LookUpRate(float AxisValue);
void LookRightRate(float AxisValue);
class APlayerController* MainPlayerController;
};
MainPlayer.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MainPlayer.h"
#include "Camera/CameraComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/Character.h"
#include "GameFramework/PlayerController.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/GameplayStatics.h"
AMainPlayer::AMainPlayer()
{
// Setup SpringArm and Camera components
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(SpringArm);
APawn::GetController();
}
void AMainPlayer::BeginPlay()
{
Super::BeginPlay();
}
// Called to bind functionality to input
void AMainPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// Mouse/KeyBoard Movement
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &AMainPlayer::MoveForward);
PlayerInputComponent->BindAxis(TEXT("LookUp"), this, &APawn::AddControllerPitchInput);
PlayerInputComponent->BindAxis(TEXT("MoveRight"), this, &AMainPlayer::MoveRight);
PlayerInputComponent->BindAxis(TEXT("LookRight"), this, &APawn::AddControllerYawInput);
// Controller
PlayerInputComponent->BindAxis(TEXT("LookUpRate"), this, &AMainPlayer::LookUpRate);
PlayerInputComponent->BindAxis(TEXT("LookRightRate"), this, &AMainPlayer::LookRightRate);
}
void AMainPlayer::MoveForward(float AxisValue)
{
AddMovementInput(GetActorForwardVector(), AxisValue);
}
void AMainPlayer::MoveRight(float AxisValue)
{
AddMovementInput(GetActorRightVector(), AxisValue);
}
void AMainPlayer::LookUpRate(float AxisValue)
{
AddControllerPitchInput(AxisValue * RotationRate * GetWorld()->GetDeltaSeconds());
}
void AMainPlayer::LookRightRate(float AxisValue)
{
AddControllerYawInput(AxisValue * RotationRate * GetWorld()->GetDeltaSeconds());
}