Hi all,
I’m super new to all this but have been poking around the programming documentation to create a simple FPS based on the following: https://docs.unrealengine.com/en-US/Programming/Tutorials/FirstPersonShooter/2/7/index.html\
Everything has been going well but my camera does not seem to be starting at the right position, but rather always starts at the origin instead (see below for example).
On the other hand, when inspected in BP, the character shows that the camera is attached properly using GetCapsuleComponent() and its relative position (see below).
Thank you guys in advance.
My character CPP file is as follows:
#include "Noob.h"
#include "Project_Retro.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
// Sets default values
ANoob::ANoob()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
FPSCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
FPSCameraComponent->SetupAttachment(GetCapsuleComponent());
FPSCameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f + BaseEyeHeight));
FPSCameraComponent->bUsePawnControlRotation = true;
}
// Called when the game starts or when spawned
void ANoob::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
// Put up a debug message for five seconds. The -1 "Key" value (first argument) indicates that we will never need to update or refresh this message.
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("We are using FPSCharacter."));
}
}
// Defines previously declared Forward_Backward function which takes in 1.0 (from input settings) and translates into movement
void ANoob::Forward_Backward(float Value)
{
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
// Defines previously declared Forward_Backward function which takes in 1.0 (from input settings) and translates into movement
void ANoob::Left_Right(float Value)
{
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
AddMovementInput(Direction, Value);
}
void ANoob::StartJump()
{
bPressedJump = true;
}
void ANoob::StopJump()
{
bPressedJump = false;
}
// Called every frame
void ANoob::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ANoob::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis("Forward_Backward", this, &ANoob::Forward_Backward);
PlayerInputComponent->BindAxis("Left_Right", this, &ANoob::Left_Right);
PlayerInputComponent->BindAxis("Yaw", this, &ANoob::AddControllerYawInput);
PlayerInputComponent->BindAxis("Pitch", this, &ANoob::AddControllerPitchInput);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ANoob::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &ANoob::StopJump);
}