Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. // ACoopPuzzleGameCharacter.h
  2.  
  3. UCLASS(Blueprintable)
  4. class ACoopPuzzleGameCharacter : public ACharacter
  5. {
  6. GENERATED_BODY()
  7.  
  8. public:
  9. ACoopPuzzleGameCharacter();
  10.  
  11. virtual void Tick(float DeltaSeconds) override;
  12.  
  13. FORCEINLINE class UCameraComponent* GetTopDownCameraComponent() const { return TopDownCameraComponent; }
  14. FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
  15.  
  16. private:
  17. /** Top down camera */
  18. UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
  19. class UCameraComponent* TopDownCameraComponent;
  20.  
  21. /** Camera boom positioning the camera above the character */
  22. UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
  23. class USpringArmComponent* CameraBoom;
  24.  
  25. public:
  26.  
  27. void MoveForward(float Value);
  28. void MoveRight(float Value);
  29. void HandleInteractInput();
  30.  
  31. };
  32.  
  33.  
  34.  
  35. // ACoopPuzzleGameCharacter.cpp
  36.  
  37. ACoopPuzzleGameCharacter::ACoopPuzzleGameCharacter()
  38. {
  39. // Set size for player capsule
  40. GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
  41.  
  42. // Don't rotate character to camera direction
  43. bUseControllerRotationPitch = false;
  44. bUseControllerRotationYaw = false;
  45. bUseControllerRotationRoll = false;
  46.  
  47. // Configure character movement
  48. GetCharacterMovement()->bOrientRotationToMovement = true; // Rotate character to moving direction
  49. GetCharacterMovement()->RotationRate = FRotator(0.f, 640.f, 0.f);
  50. GetCharacterMovement()->bConstrainToPlane = true;
  51. GetCharacterMovement()->bSnapToPlaneAtStart = true;
  52.  
  53. // Create a camera boom...
  54. CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
  55. CameraBoom->SetupAttachment(RootComponent);
  56. CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when character does
  57. CameraBoom->TargetArmLength = 800.f;
  58. CameraBoom->RelativeRotation = FRotator(-60.f, 0.f, 0.f);
  59. CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level
  60.  
  61. // Create a camera...
  62. TopDownCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera"));
  63. TopDownCameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
  64. TopDownCameraComponent->bUsePawnControlRotation = false;
  65.  
  66. // Activate ticking in order to update the cursor every frame.
  67. PrimaryActorTick.bCanEverTick = true;
  68. PrimaryActorTick.bStartWithTickEnabled = true;
  69. }
  70.  
  71. void ACoopPuzzleGameCharacter::Tick(float DeltaSeconds)
  72. {
  73. Super::Tick(DeltaSeconds);
  74. }
  75.  
  76.  
  77. void ACoopPuzzleGameCharacter::MoveForward(float Value)
  78. {
  79. if ((Controller != NULL) && (Value != 0.0f))
  80. {
  81. const FRotator Rotation = GetControlRotation();
  82. const FRotator YawRotation(0, Rotation.Yaw, 0);
  83.  
  84. const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
  85. AddMovementInput(Direction, Value);
  86. }
  87. }
  88.  
  89. void ACoopPuzzleGameCharacter::MoveRight(float Value)
  90. {
  91. if ((Controller != NULL) && (Value != 0.0f))
  92. {
  93. const FRotator Rotation = GetControlRotation();
  94. const FRotator YawRotation(0, Rotation.Yaw, 0);
  95.  
  96. const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
  97. AddMovementInput(Direction, Value);
  98. }
  99. }
  100.  
  101. void ACoopPuzzleGameCharacter::HandleInteractInput()
  102. {
  103. UE_LOG(LogTemp, Warning, TEXT("ACoopPuzzleGameCharacter::HandleInteractInput Called"));
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement