Hi,
I’m trying to build a game in unreal and one of the first things I’m trying to do is to make a box move in response to player input.
I followed the Udemy Unreal Engine 5 C++ Developer: Learn C++ & Make Video Games Course and I can’t tell what I did wrong. The specific video is 121 (handling input).
Here is my code in “MovementBox.cpp”:
#include “MovementBox.h”
#include “Components/InputComponent.h”
#include “Components/CapsuleComponent.h”
// Sets default values
AMovementBox::AMovementBox()
{
// 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;
CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule Collider"));
}
// Called when the game starts or when spawned
void AMovementBox::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMovementBox::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AMovementBox::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("Steering"), this, &AMovementBox::MoveRight);
}
void AMovementBox::MoveRight(float InputThrottle)
{
UE_LOG(LogTemp, Warning, TEXT(“Input Throttle: %f”), InputThrottle);
}
And here is my code in “MovementBox.h”:
#pragma once
#include “CoreMinimal.h”
#include “GameFramework/Pawn.h”
#include “MovementBox.generated.h”
UCLASS()
class NEA_7670_API AMovementBox : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn’s properties
AMovementBox();
// 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()
class UCapsuleComponent* CapsuleComp;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
private:
void MoveRight(float InputThrottle);
};
I have 6 errors in the editor, although the project builds fine without it and other projects of mine work fine with them, so I’m not sure if they’re much of an issue:
If it adds anything, I have VR plugins installed and a VRCharacter from the VRExpansionPlugin. I have a blueprint child class of the movementbox, which has a capsule comp and a cube static mesh. I have not changed anything in the editor for this pawn.
Thanks for your help.