|
|
|
|
| #include "PockmonCharacter.h"
|
| #include "Engine/LocalPlayer.h"
|
| #include "Camera/CameraComponent.h"
|
| #include "Components/CapsuleComponent.h"
|
| #include "GameFramework/CharacterMovementComponent.h"
|
| #include "GameFramework/SpringArmComponent.h"
|
| #include "GameFramework/Controller.h"
|
| #include "EnhancedInputComponent.h"
|
| #include "EnhancedInputSubsystems.h"
|
| #include "InputActionValue.h"
|
| #include "Pockmon.h"
|
|
|
| APockmonCharacter::APockmonCharacter()
|
| {
|
|
|
| GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
|
|
|
|
|
| bUseControllerRotationPitch = false;
|
| bUseControllerRotationYaw = false;
|
| bUseControllerRotationRoll = false;
|
|
|
|
|
| GetCharacterMovement()->bOrientRotationToMovement = true;
|
| GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f);
|
|
|
|
|
|
|
| GetCharacterMovement()->JumpZVelocity = 500.f;
|
| GetCharacterMovement()->AirControl = 0.35f;
|
| GetCharacterMovement()->MaxWalkSpeed = 500.f;
|
| GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
|
| GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;
|
| GetCharacterMovement()->BrakingDecelerationFalling = 1500.0f;
|
|
|
|
|
| CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
|
| CameraBoom->SetupAttachment(RootComponent);
|
| CameraBoom->TargetArmLength = 400.0f;
|
| CameraBoom->bUsePawnControlRotation = true;
|
|
|
|
|
| FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
|
| FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
|
| FollowCamera->bUsePawnControlRotation = false;
|
|
|
|
|
|
|
| }
|
|
|
| void APockmonCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
| {
|
|
|
| if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(PlayerInputComponent)) {
|
|
|
|
|
| EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump);
|
| EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
|
|
|
|
|
| EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &APockmonCharacter::Move);
|
| EnhancedInputComponent->BindAction(MouseLookAction, ETriggerEvent::Triggered, this, &APockmonCharacter::Look);
|
|
|
|
|
| EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &APockmonCharacter::Look);
|
| }
|
| else
|
| {
|
| UE_LOG(LogPockmon, Error, TEXT("'%s' Failed to find an Enhanced Input component! This template is built to use the Enhanced Input system. If you intend to use the legacy system, then you will need to update this C++ file."), *GetNameSafe(this));
|
| }
|
| }
|
|
|
| void APockmonCharacter::Move(const FInputActionValue& Value)
|
| {
|
|
|
| FVector2D MovementVector = Value.Get<FVector2D>();
|
|
|
|
|
| DoMove(MovementVector.X, MovementVector.Y);
|
| }
|
|
|
| void APockmonCharacter::Look(const FInputActionValue& Value)
|
| {
|
|
|
| FVector2D LookAxisVector = Value.Get<FVector2D>();
|
|
|
|
|
| DoLook(LookAxisVector.X, LookAxisVector.Y);
|
| }
|
|
|
| void APockmonCharacter::DoMove(float Right, float Forward)
|
| {
|
| if (GetController() != nullptr)
|
| {
|
|
|
| const FRotator Rotation = GetController()->GetControlRotation();
|
| const FRotator YawRotation(0, Rotation.Yaw, 0);
|
|
|
|
|
| const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
|
|
|
|
| const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
|
|
|
|
| AddMovementInput(ForwardDirection, Forward);
|
| AddMovementInput(RightDirection, Right);
|
| }
|
| }
|
|
|
| void APockmonCharacter::DoLook(float Yaw, float Pitch)
|
| {
|
| if (GetController() != nullptr)
|
| {
|
|
|
| AddControllerYawInput(Yaw);
|
| AddControllerPitchInput(Pitch);
|
| }
|
| }
|
|
|
| void APockmonCharacter::DoJumpStart()
|
| {
|
|
|
| Jump();
|
| }
|
|
|
| void APockmonCharacter::DoJumpEnd()
|
| {
|
|
|
| StopJumping();
|
| }
|
|
|