MyController.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "PlayerCharacterController.generated.h"
class APlayerCharacter;
/**
*
*/
UCLASS()
class OWAG_V3_API APlayerCharacterController : public APlayerController
{
GENERATED_BODY()
public:
/*Base functions*/
virtual void BeginPlay() override;
virtual void SetupInputComponent() override;
/*Base variables*/
APlayerCharacter* ControlledCharacter;
MyController.cpp
#include "PlayerCharacterController.h"
#include "Kismet/GameplayStatics.h"
void APlayerCharacterController::BeginPlay()
{
Super::BeginPlay();
ControlledCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
if (ControlledCharacter == nullptr) {UE_LOG(LogTemp, Warning, TEXT("ControlledPlayer is null in player controller!")) return;}
}
void APlayerCharacterController::SetupInputComponent()
{
Super::SetupInputComponent();
/*Movement Bindings*/
InputComponent->BindAxis("MoveForward", this, &APlayerCharacterController::MoveForward);
InputComponent->BindAxis("MoveRight", this, &APlayerCharacterController::MoveRight);
InputComponent->BindAction("Jump", IE_Pressed, this, &APlayerCharacterController::StartJump);
InputComponent->BindAction("Jump", IE_Released, this, &APlayerCharacterController::EndJump);
InputComponent->BindAction("Sprint", IE_Pressed, this, &APlayerCharacterController::StartSprint);
InputComponent->BindAction("Sprint", IE_Released, this, &APlayerCharacterController::EndSprint);
/*Camera Bindings*/
InputComponent->BindAxis("LookHorizontal", this, &APlayerCharacterController::AddYawInput);
InputComponent->BindAxis("LookVertical", this, &APlayerCharacterController::AddPitchInput);
}
void APlayerCharacterController::MoveForward(float Axis)
{
if (Axis != 0.f)
{
float ClampedAxis = FMath::Clamp(Axis, -1.f, 1.f);
FVector Direction = ControlledCharacter->GetActorForwardVector();
ControlledCharacter->AddMovementInput(Direction, ClampedAxis);
}
}
void APlayerCharacterController::MoveRight(float Axis)
{
if (Axis != 0.f)
{
float ClampedAxis = FMath::Clamp(Axis, -1.f, 1.f);
FVector Direction = ControlledCharacter->GetActorRightVector();
ControlledCharacter->AddMovementInput(Direction, ClampedAxis);
}
}
void APlayerCharacterController::StartJump()
{
ControlledCharacter->bPressedJump = true;
}
void APlayerCharacterController::EndJump()
{
ControlledCharacter->bPressedJump = false;
}
void APlayerCharacterController::StartSprint()
{
ControlledCharacter->GetCharacterMovement()->MaxWalkSpeed = 850.f;
}
void APlayerCharacterController::EndSprint()
{
ControlledCharacter->GetCharacterMovement()->MaxWalkSpeed = 600.f;
}
Not sure exactly what is happening here, took a short break from coding due to time constraints but I am getting back into it and I am having some errors with simple code and I am not sure if I am just missing something. In my controller.cpp I am getting an error stating that “pointer to incomplete class type is not allowed” in reference to my ControlledCharacter variable. (Just as a quick note, my functions for my inputs are declared in my header, I just didn’t include them due to them not not causing this issue, I’m assuming anyway). The odd thing is I didn’t have the error at all and could compile fine for a while, up until I reach the point I was adding in jumping, then the error appeared and nothing I do seems to solve it. Is it something with my code or is visual studio just being odd and if it is just visual studio does anyone have any advice or work around to get this working again?