Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ACoopPuzzleGameCharacter.h
- UCLASS(Blueprintable)
- class ACoopPuzzleGameCharacter : public ACharacter
- {
- GENERATED_BODY()
- public:
- ACoopPuzzleGameCharacter();
- virtual void Tick(float DeltaSeconds) override;
- FORCEINLINE class UCameraComponent* GetTopDownCameraComponent() const { return TopDownCameraComponent; }
- FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
- private:
- /** Top down camera */
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
- class UCameraComponent* TopDownCameraComponent;
- /** Camera boom positioning the camera above the character */
- UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
- class USpringArmComponent* CameraBoom;
- public:
- void MoveForward(float Value);
- void MoveRight(float Value);
- void HandleInteractInput();
- };
- // ACoopPuzzleGameCharacter.cpp
- ACoopPuzzleGameCharacter::ACoopPuzzleGameCharacter()
- {
- // Set size for player capsule
- GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
- // Don't rotate character to camera direction
- bUseControllerRotationPitch = false;
- bUseControllerRotationYaw = false;
- bUseControllerRotationRoll = false;
- // Configure character movement
- GetCharacterMovement()->bOrientRotationToMovement = true; // Rotate character to moving direction
- GetCharacterMovement()->RotationRate = FRotator(0.f, 640.f, 0.f);
- GetCharacterMovement()->bConstrainToPlane = true;
- GetCharacterMovement()->bSnapToPlaneAtStart = true;
- // Create a camera boom...
- CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
- CameraBoom->SetupAttachment(RootComponent);
- CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when character does
- CameraBoom->TargetArmLength = 800.f;
- CameraBoom->RelativeRotation = FRotator(-60.f, 0.f, 0.f);
- CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level
- // Create a camera...
- TopDownCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera"));
- TopDownCameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
- TopDownCameraComponent->bUsePawnControlRotation = false;
- // Activate ticking in order to update the cursor every frame.
- PrimaryActorTick.bCanEverTick = true;
- PrimaryActorTick.bStartWithTickEnabled = true;
- }
- void ACoopPuzzleGameCharacter::Tick(float DeltaSeconds)
- {
- Super::Tick(DeltaSeconds);
- }
- void ACoopPuzzleGameCharacter::MoveForward(float Value)
- {
- if ((Controller != NULL) && (Value != 0.0f))
- {
- const FRotator Rotation = GetControlRotation();
- const FRotator YawRotation(0, Rotation.Yaw, 0);
- const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
- AddMovementInput(Direction, Value);
- }
- }
- void ACoopPuzzleGameCharacter::MoveRight(float Value)
- {
- if ((Controller != NULL) && (Value != 0.0f))
- {
- const FRotator Rotation = GetControlRotation();
- const FRotator YawRotation(0, Rotation.Yaw, 0);
- const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
- AddMovementInput(Direction, Value);
- }
- }
- void ACoopPuzzleGameCharacter::HandleInteractInput()
- {
- UE_LOG(LogTemp, Warning, TEXT("ACoopPuzzleGameCharacter::HandleInteractInput Called"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement