Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. //ACoopPuzzleGamePlayerController.h
  2.  
  3. CLASS()
  4. class ACoopPuzzleGamePlayerController : public APlayerController
  5. {
  6. GENERATED_BODY()
  7.  
  8. public:
  9. ACoopPuzzleGamePlayerController();
  10.  
  11. virtual void BeginPlay() override;
  12.  
  13. protected:
  14.  
  15. virtual void SetupInputComponent() override;
  16.  
  17. protected:
  18.  
  19. // Reference to the pawn
  20. class ACoopPuzzleGameCharacter* myCharacter;
  21.  
  22. ///// Input Actions //////
  23. UFUNCTION(BlueprintCallable, Category = "Input")
  24. void MoveForward(float Value);
  25.  
  26. UFUNCTION(BlueprintCallable, Category = "Input")
  27. void MoveRight(float Value);
  28.  
  29. UFUNCTION(BlueprintCallable, Category = "Inputs")
  30. void FaceButtonBottom();
  31. ///// Input Actions //////
  32. };
  33.  
  34.  
  35.  
  36. //ACoopPuzzleGamePlayerController.cpp
  37.  
  38. ACoopPuzzleGamePlayerController::ACoopPuzzleGamePlayerController()
  39. {
  40. DefaultMouseCursor = EMouseCursor::Crosshairs;
  41. }
  42.  
  43. void ACoopPuzzleGamePlayerController::BeginPlay()
  44. {
  45. Super::BeginPlay();
  46.  
  47. // Get reference to the character controllerd by this player controller
  48. APawn* const pawn = GetPawn();
  49. if (pawn != nullptr)
  50. {
  51. myCharacter = Cast<ACoopPuzzleGameCharacter>(pawn);
  52. }
  53. }
  54.  
  55. // Setup input controller
  56. void ACoopPuzzleGamePlayerController::SetupInputComponent()
  57. {
  58. Super::SetupInputComponent();
  59.  
  60. // Input controller
  61. InputComponent->BindAxis("MoveForward", this, &ACoopPuzzleGamePlayerController::MoveForward);
  62. InputComponent->BindAxis("MoveRight", this, &ACoopPuzzleGamePlayerController::MoveRight);
  63. }
  64.  
  65.  
  66. void ACoopPuzzleGamePlayerController::MoveForward(float Value)
  67. {
  68. if (Value == 0.0f) return;
  69.  
  70. // The character is in charge of moving the mesh not the player controller
  71. if (myCharacter != nullptr)
  72. {
  73. myCharacter->MoveForward(Value);
  74. }
  75. }
  76.  
  77. void ACoopPuzzleGamePlayerController::MoveRight(float Value)
  78. {
  79. if (Value == 0.0f) return;
  80.  
  81. // The character is in charge of moving the mesh not the player controller
  82. if (myCharacter != nullptr)
  83. {
  84. myCharacter->MoveRight(Value);
  85. }
  86. }
  87.  
  88. void ACoopPuzzleGamePlayerController::FaceButtonBottom()
  89. {
  90. if (myCharacter != nullptr)
  91. {
  92. myCharacter->HandleInteractInput();
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement