I have created a character for my game, and a custom player controller to hold all my key bindings and functions to move the player. But I don’t know how to call the character’s AddMovementInput method in my Player Controller class. Do you know how to do it?
void ABZPlayerController::MoveForward(float Value)
{
if ((this != NULL) && (Value != 0.0f))
{
//Find out which way is forward
FRotator Rotation = this->GetControlRotation();
//Add movement to that direction
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
ABZCharacter->AddMovementInput(Direction, Value); //HOW TO CALL THIS
}
}
I don’t know if I understand your question to be honest. But I guess you mean how to get the reference, if that is the case, then here is the solution.
void ABZPlayerController::MoveForward(float Value)
{
if ((this != NULL) && (Value != 0.0f))
{
//Find out which way is forward
FRotator Rotation = this->GetControlRotation();
//Add movement to that direction
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
//GetControlledPawn() gives you the reference you need, you don't need to cast in this case but anyways.
ABZCharacter *MyCharacterReference = Cast<ABZCharacter>(GetControlledPawn());
MyCharacterReference ->AddMovementInput(Direction, Value);
}
}
Make sure to include the header file of your character before you cast.