
Announcement
Collapse
No announcement yet.
Help calling my character's method in the playercontroller
Collapse
X
-
DennyR repliedI 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.
Code: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.
Leave a comment:
-
Young_Wolf started a topic Help calling my character's method in the playercontrollerHelp calling my character's method in the playercontroller
Hello,
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?
Code: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 } }
Tags: None
Leave a comment: