UE4 C++ Tutorial - How To Move Pawns - Pawn Movement - UE4 / Unreal Engine 4 Intro to C++ - YouTube I have followed exactly everything on this tutorial and I cannot possess the pawn for the life of me , I changed the game mode, made a pawn class and made a BP version and added that as my default pawn, added a spring arm and camera to my pawn BP . And then add it into my scene and press play , nothing happens, please help?
Here’s the header and cpp
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include “CoreMinimal.h”
#include “GameFramework/Pawn.h”
#include “PawnMovement.generated.h”
UCLASS()
class MYPROJECT89_API APawnMovement : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn’s properties
APawnMovement();
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;
void MoveRight(float Value);
void MoveForward(float Value);
UPROPERTY(EditAnywhere, Category = "Movement Speed")
float MovementSpeed = 500.0f;
FVector MovementDirection;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include “PawnMovement.h”
// Sets default values
APawnMovement::APawnMovement()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
}
void APawnMovement::BeginPlay()
{
Super::BeginPlay();
}
void APawnMovement::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//updating the movement so on every tick i move some
if (!MovementDirection.IsZero())
{
const FVector NewLocation = GetActorLocation() + (MovementDirection * DeltaTime * MovementSpeed);
SetActorLocation(NewLocation);
}
}
void APawnMovement::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
//input bindings
InputComponent->BindAxis(TEXT(“MoveForward”), this, &APawnMovement::MoveForward);
InputComponent->BindAxis(TEXT(“MoveRight”), this, &APawnMovement::MoveRight);
}
void APawnMovement::MoveRight(float Value)
{
//when buttons are pressed for move right it’ll go from -1 to 1 for movement input, same on y
MovementDirection.X = FMath::Clamp(Value, - 1.0f, 1.0f);
}
void APawnMovement::MoveForward(float Value)
{
//movement on y axis
MovementDirection.Y = FMath::Clamp(Value, -1.0f, 1.0f);
}