As near as I can tell I’ve set this up correctly but the spring arm/camera does not seem to be position correctly relative to the tank.
Using the exact same settings as I saw in the video my camera view seems to be below the floor and does not follow the tank when moving.
#include "Tank.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
ATank::ATank()
{
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(SpringArm);
}
void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
}
void ATank::Move(float Value)
{
FVector DeltaLocation = FVector::ZeroVector;
// X = Value * DeltaTime * Speed
DeltaLocation.X = Value * GetWorld()->DeltaTimeSeconds * Speed;
AddActorLocalOffset(DeltaLocation, true);
}