Hi I tried making my own character movement component class and I want to make a character class that use it. I tried following this tutorial but I doesn’t seem to work. I get a compiler error saying that the constructor already has a body. Currently I am just trying to get the character to use the right movement component but the plan is to implement custom movement modes. Any help would be much appreciated!
Character Header:
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "AdvCharMovementComponent.h"
#include "AdvancedCharacter.generated.h"
UCLASS()
class ADVCHARPROJ_API AAdvancedCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
//AAdvancedCharacter(const FObjectInitializer& ObjectInitializer);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
Character Source:
#include "AdvancedCharacter.h"
// Sets default values
AAdvancedCharacter::AAdvancedCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<UAdvCharMovementComponent>(ACharacter::CharacterMovementComponentName))
{
// 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;
}
// Called when the game starts or when spawned
void AAdvancedCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AAdvancedCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AAdvancedCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
Movement Component Header:
#include "CoreMinimal.h"
#include "EngineGlobals.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "AdvCharMovementComponent.generated.h"
#define PRINT(x) if(GEngine){GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Yellow, TEXT(x));}
UENUM(BlueprintType)
enum ECustomMovementMode
{
CUSTOM_prone UMETA(DisplayName = "Prone_mode"),
CUSTOM_cover UMETA(DisplayName = "Prone_mode")
};
/**
*
*/
UCLASS()
class ADVCHARPROJ_API UAdvCharMovementComponent : public UCharacterMovementComponent
{
GENERATED_UCLASS_BODY()
protected:
virtual void PhysCustom(float deltaTime, int32 Iterations) override;
void PhysCustomProne(float deltaTime, int32 Iterations);
void PhysCustomCover(float deltaTime, int32 Iterations);
};
Movement Component Source:
#include "AdvCharMovementComponent.h"
void UAdvCharMovementComponent::PhysCustom(float deltaTime, int32 Iterations) {
switch (CustomMovementMode)
{
case CUSTOM_prone:
PhysCustomProne(deltaTime,Iterations);
break;
case CUSTOM_cover:
PhysCustomCover(deltaTime, Iterations);
break;
default:
break;
}
}
void UAdvCharMovementComponent::PhysCustomCover(float deltaTime, int32 Iterations) {
PRINT("Cover");
PhysWalking(deltaTime, Iterations);
}
void UAdvCharMovementComponent::PhysCustomProne(float deltaTime, int32 Iterations) {
PRINT("Prone");
PhysWalking(deltaTime, Iterations);
}