I want create custom movement for climbing on ladder but I propably misunderstood the idea how to do it.
My ClimbingMovementComponent.h
#include "GameFramework/CharacterMovementComponent.h"
#include "ClimbingMovementComponent.generated.h"
UENUM(BlueprintType)
enum ECustomMovementMode
{
TESTMOVE_Climbing UMETA(DisplayName = "Climbing"),
TESTMOVE_Walking UMETA(DisplayName = "Walking")
};
UCLASS()
class GAME_API UClimbingMovementComponent : public UCharacterMovementComponent
{
GENERATED_BODY()
public:
UPROPERTY(Category = MovementMode, BlueprintReadOnly)
TEnumAsByte<enum ECustomMovementMode> NewCustomMovementMode;
protected:
virtual void PhysCustom(float deltaTime, int32 Iterations) override;
UClimbingMovementComponent(const class FObjectInitializer& ObjectInitializer);
void PhysCustomClimb(float deltaTime, int32 Iterations);
void PhysCustomWalk(float deltaTime, int32 Iterations);
};
And ClimbingMovementComponent.cpp
#include "Game.h"
#include "ClimbingMovementComponent.h"
UClimbingMovementComponent::UClimbingMovementComponent(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}
void UClimbingMovementComponent::PhysCustom(float deltaTime, int32 Iterations)
{
switch (CustomMovementMode)
{
case TESTMOVE_Climbing:
PhysCustomClimb(deltaTime, Iterations);
break;
case TESTMOVE_Walking:
PhysCustomElse(deltaTime, Iterations);
break;
default:
break;
}
}
void UClimbingMovementComponent::PhysCustomClimb(float deltaTime, int32 Iterations)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Climb"));
}
void UClimbingMovementComponent::PhysCustomWalk(float deltaTime, int32 Iterations)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Walk"));
}
Also I added this to my character :
APlayerGhost::APlayerGhost(const class FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer.SetDefaultSubobjectClass<UClimbingMovementComponent>(ACharacter::CharacterMovementComponentName))
And set movement to custom:
GetCharacterMovement()->SetMovementMode(MOVE_Custom, TESTMOVE_Climbing);
Build succeeded but I can’t get it working. What I’m doing wrong ?
Is this a way how to achieve custom movement mode ? Is there any better way then create new class ?
EDIT: My bug was outside this solution. So this aproach is allright.