My Tank doesn’t move no matter what I try and I believe my code is the same as the lecture. I also have the auto possession and blueprint set up the same.
image|690x398
#pragma once
#include "CoreMinimal.h"
#include "PawnBase.h"
#include "PawnTank.generated.h"
class USpringArmComponent;
class UCameraComponent;
UCLASS()
class TOONTANKS_API APawnTank : public APawnBase
{
GENERATED_BODY()
private:
UPROPERTY(VisibleAnywhere, BluePrintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
USpringArmComponent* SpringArm;
UPROPERTY(VisibleAnywhere, BluePrintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UCameraComponent* Camera;
FVector MoveDirection;
FQuat RotationDirection;
float MoveSpeed = 100.f;
float RotateSpeed = 100.f;
void CalculateMoveInput(float Value);
void CalculateRotateInput(float Value);
void Move();
void Rotate();
public:
APawnTank();
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to inputs
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};
#include “PawnTank.h”
#include “GameFramework/SpringArmComponent.h”
#include “Camera/CameraComponent.h”
APawnTank::APawnTank()
{
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(SpringArm);
}
// Called when the game starts or when spawned
void APawnTank::BeginPlay()
{
Super::BeginPlay();
Rotate();
Move();
}
// Called every frame
void APawnTank::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void APawnTank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis("MoveForward", this, &APawnTank::CalculateMoveInput);
PlayerInputComponent->BindAxis("Turn", this, &APawnTank::CalculateRotateInput);
}
void APawnTank::CalculateMoveInput(float Value)
{
MoveDirection = FVector(Value * MoveSpeed * GetWorld()->DeltaTimeSeconds, 0, 0);
}
void APawnTank::CalculateRotateInput(float Value)
{
float RotateAmount = Value * RotateSpeed * GetWorld()->DeltaTimeSeconds;
FRotator Rotation = FRotator(0, RotateAmount, 0);
RotationDirection = FQuat(Rotation);
}
void APawnTank::Move()
{
AddActorLocalOffset(MoveDirection, true);
}
void APawnTank::Rotate()
{
AddActorLocalRotation(RotationDirection, true);
}