I have some serious issues with implementing custom movement modes or states, I searched on the forums and I don’t quite get how people is managing to implement their custom movement modes. I followed rama’s tutorials and I feel them some incomplete, and I found the topic itself a little bit confusing and hard to implement.
So I want to create a new movement state for my character, what I want to do is to change movement state to CUSTOM from character.cpp that state will call a function of my custom movement component class, the code works, the communication between classes is working, but the character is not able to move. Here is my code:
MOVEMENT COMPONENT.H
enum ECustomMovementMode
{
CMOVE_WallRunning UMETA(DisplayName = "Wall Running"),
};
UCLASS()
class UWallRunMovComp : public UCharacterMovementComponent
{
GENERATED_BODY()
public:
TEnumAsByte<enum ECustomMovementMode> NewCustomMovementMode;
APlayerCameraManager* GPCM;
APlayerController* PC;
FHitResult CT_OutHit;
FCollisionQueryParams TraceParams;
FTimerHandle WallRun_Clock;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = WallRun)
float TimeOnWalls;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = WallRun)
float DistanceTolerance;
protected:
virtual void PhysCustom(float deltaTime, int32 Iterations) override;
UWallRunMovComp(const class FObjectInitializer& ObjectInitializer);
void VWallRun(float deltaTime, int32 Iterations);
};
MOVEMENT COMPONENT.CPP
UWallRunMovComp::UWallRunMovComp(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
TimeOnWalls = 3.f;
DistanceTolerance = 150.f;
}
void UWallRunMovComp::PhysCustom(float deltaTime, int32 Iterations)
{
switch (CustomMovementMode)
{
case CMOVE_WallRunning:
VWallRun(deltaTime, Iterations);
break;
default:
break;
}
}
void UWallRunMovComp::VWallRun(float deltaTime, int32 Iterations)
{
this->GPCM = UGameplayStatics::GetPlayerCameraManager(this, 0);
this->PC = UGameplayStatics::GetPlayerController(this, 0);
GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Yellow,"lol");
}
CHARACTER.CPP (Only function that changes movement mode)
void ARunnerCharacter::V_WallRun()
{
if (GetCharacterMovement()->MovementMode == 3)
{
UWallRunMovComp* CustomCharMovementComp = Cast<UWallRunMovComp>(CharacterMovement);
if (CustomCharMovementComp)
GetCharacterMovement()->SetMovementMode(MOVE_Custom, CMOVE_WallRunning);
}
}
the build compiles succesfully and when I Jump and press the “special” input keys, the game is printing the string “lol” just to make sure it works, I have some custom code there to perform the movement which compiles correctly too, but the character is just standing in the air doing nothing, I can shoot and look around but I can’t move or jump, I am able to crouch too (Custom crouch but not in a custom movement mode)
¿What am I doing wrong?
Thanks