Announcement

Collapse
No announcement yet.

Help calling my character's method in the playercontroller

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help 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
    	}
    }
    Raise the Black Flag!

    - [TUT]: HTTP GET Request in C++
    - [Tool]: Game Site Tracker website for your project
    - [Website]: Website for my game Leviathan

    #2
    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.

    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.

    Comment


      #3
      Yes! Thanks, that is what I exactly wanted Big thanks !
      Raise the Black Flag!

      - [TUT]: HTTP GET Request in C++
      - [Tool]: Game Site Tracker website for your project
      - [Website]: Website for my game Leviathan

      Comment

      Working...
      X