2025-02-12 19:10:23 +01:00
|
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Player/ExoPlayerController.h"
|
|
|
|
|
|
#include "EnhancedInputComponent.h"
|
|
|
|
|
|
#include "EnhancedInputSubsystems.h"
|
2025-02-21 15:59:46 +01:00
|
|
|
|
#include "Characters/ExoPlayerCharacter.h"
|
2025-02-12 19:10:23 +01:00
|
|
|
|
#include "GameFramework/Character.h"
|
2025-02-20 18:00:26 +01:00
|
|
|
|
#include "GameFramework/CharacterMovementComponent.h"
|
2025-02-12 19:10:23 +01:00
|
|
|
|
|
|
|
|
|
|
AExoPlayerController::AExoPlayerController()
|
|
|
|
|
|
{
|
|
|
|
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::BeginPlay()
|
|
|
|
|
|
{
|
|
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
|
check(InputContext);
|
2025-02-20 18:00:26 +01:00
|
|
|
|
|
2025-02-21 15:59:46 +01:00
|
|
|
|
PlayerCharacter = Cast<AExoPlayerCharacter>(GetPawn<ACharacter>());
|
|
|
|
|
|
check(PlayerCharacter);
|
|
|
|
|
|
|
2025-02-12 19:10:23 +01:00
|
|
|
|
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
|
|
|
|
|
|
|
|
|
|
|
if (Subsystem)
|
|
|
|
|
|
{
|
|
|
|
|
|
Subsystem->AddMappingContext(InputContext, 0);
|
|
|
|
|
|
}
|
2025-02-21 15:59:46 +01:00
|
|
|
|
|
2025-02-17 15:28:18 +01:00
|
|
|
|
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
|
2025-02-21 20:42:52 +01:00
|
|
|
|
ShootingComponent = PlayerCharacter->FindComponentByClass<UShootingComponent>();
|
2025-02-22 23:31:23 +01:00
|
|
|
|
|
2025-03-07 11:11:22 +01:00
|
|
|
|
// Ustawianie w komponencie poruszania pr<70>dko<6B>ci zapisanej w characterze
|
2025-02-22 23:31:23 +01:00
|
|
|
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
|
2025-02-12 19:10:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerTick(float DeltaTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
Super::PlayerTick(DeltaTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::SetupInputComponent()
|
|
|
|
|
|
{
|
|
|
|
|
|
Super::SetupInputComponent();
|
|
|
|
|
|
|
|
|
|
|
|
UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(InputComponent);
|
|
|
|
|
|
|
|
|
|
|
|
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Move);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Look);
|
2025-02-17 15:28:18 +01:00
|
|
|
|
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact);
|
2025-02-20 18:00:26 +01:00
|
|
|
|
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerJump);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(DodgeAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerDodge);
|
2025-02-22 23:31:23 +01:00
|
|
|
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerStartCrouch);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AExoPlayerController::PlayerStopCrouch);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerStartSprint);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this, &AExoPlayerController::PlayerStopSprint);
|
2025-02-21 20:42:52 +01:00
|
|
|
|
EnhancedInputComponent->BindAction(ShootAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerShoot);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerAim);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(MeleAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerMeleAttack);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(ChangeWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerChangeWeapon);
|
|
|
|
|
|
EnhancedInputComponent->BindAction(ReloadAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerReload);
|
2025-02-12 19:10:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::Move(const FInputActionValue& InputActionValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
const FVector2D InputAxisVector = InputActionValue.Get<FVector2D>();
|
|
|
|
|
|
const FRotator Rotation = GetControlRotation();
|
|
|
|
|
|
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
|
|
|
|
|
|
|
|
|
|
|
|
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
|
|
|
|
|
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
|
|
|
|
|
|
|
|
|
|
|
if (PlayerCharacter)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerCharacter->AddMovementInput(ForwardDirection, InputAxisVector.X);
|
|
|
|
|
|
PlayerCharacter->AddMovementInput(RightDirection, InputAxisVector.Y);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::Look(const FInputActionValue& InputActionValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
FVector2D InputAxisVector = InputActionValue.Get<FVector2D>();
|
|
|
|
|
|
|
|
|
|
|
|
AddYawInput(InputAxisVector.X);
|
|
|
|
|
|
AddPitchInput(InputAxisVector.Y);
|
|
|
|
|
|
}
|
2025-02-17 15:28:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
2025-02-21 20:42:52 +01:00
|
|
|
|
void AExoPlayerController::Interact()
|
2025-02-17 15:28:18 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (InteractionComponent->InteractedActor)
|
|
|
|
|
|
IInteractable::Execute_Interact(InteractionComponent->InteractedActor);
|
|
|
|
|
|
}
|
2025-02-20 18:00:26 +01:00
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerJump()
|
|
|
|
|
|
{
|
2025-02-22 23:31:23 +01:00
|
|
|
|
PlayerCharacter->Jump();
|
2025-02-20 18:00:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerDodge()
|
|
|
|
|
|
{
|
|
|
|
|
|
UE_LOG(LogTemp, Error, TEXT("Player Dodge"));
|
|
|
|
|
|
|
|
|
|
|
|
if (PlayerCharacter->GetCharacterMovement()->IsFalling()) return;
|
|
|
|
|
|
|
2025-02-22 23:31:23 +01:00
|
|
|
|
if (PlayerCharacter->GetCharacterMovement()->IsCrouching()) return;
|
|
|
|
|
|
|
2025-02-20 18:00:26 +01:00
|
|
|
|
if (!CanDodge) return;
|
|
|
|
|
|
|
|
|
|
|
|
CanDodge = false;
|
|
|
|
|
|
|
|
|
|
|
|
FVector DodgeDirection = PlayerCharacter->GetVelocity().GetSafeNormal();
|
|
|
|
|
|
DodgeDirection.Z = 0.f;
|
|
|
|
|
|
|
|
|
|
|
|
if (DodgeDirection.IsNearlyZero())
|
|
|
|
|
|
DodgeDirection = PlayerCharacter->GetActorForwardVector();
|
|
|
|
|
|
|
2025-02-22 23:31:23 +01:00
|
|
|
|
PlayerCharacter->LaunchCharacter(DodgeDirection * PlayerCharacter->DodgeForce, true, true);
|
2025-02-20 18:00:26 +01:00
|
|
|
|
|
2025-02-22 23:31:23 +01:00
|
|
|
|
GetWorldTimerManager().SetTimer(DodgeCooldownTimer, this, &AExoPlayerController::ResetDodge, PlayerCharacter->DodgeCooldown, false);
|
2025-02-20 18:00:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::ResetDodge()
|
|
|
|
|
|
{
|
|
|
|
|
|
CanDodge = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 23:31:23 +01:00
|
|
|
|
void AExoPlayerController::PlayerStartCrouch()
|
2025-02-20 18:00:26 +01:00
|
|
|
|
{
|
2025-02-22 23:31:23 +01:00
|
|
|
|
PlayerCharacter->Crouch();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerStopCrouch()
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerCharacter->UnCrouch();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerStartSprint()
|
|
|
|
|
|
{
|
|
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Start sprint"));
|
|
|
|
|
|
|
|
|
|
|
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->SprintSpeed;
|
2025-02-20 18:00:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 23:31:23 +01:00
|
|
|
|
void AExoPlayerController::PlayerStopSprint()
|
2025-02-20 18:00:26 +01:00
|
|
|
|
{
|
2025-02-22 23:31:23 +01:00
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("Stop sprint"));
|
2025-02-20 18:00:26 +01:00
|
|
|
|
|
2025-02-22 23:31:23 +01:00
|
|
|
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
|
2025-02-20 18:00:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerShoot()
|
|
|
|
|
|
{
|
2025-02-21 20:42:52 +01:00
|
|
|
|
ShootingComponent->Shoot();
|
2025-02-20 18:00:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerAim()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerMeleAttack()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerChangeWeapon()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AExoPlayerController::PlayerReload()
|
|
|
|
|
|
{
|
2025-02-22 01:28:07 +01:00
|
|
|
|
ShootingComponent->Reload();
|
2025-02-20 18:00:26 +01:00
|
|
|
|
}
|