Added interface for damage. Added shooting component with simple shooting system. Fix missing action bindings in player controller. Added cylinder mesh to ExoEnemy and place him on TestMap.
157 lines
4.7 KiB
C++
157 lines
4.7 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Player/ExoPlayerController.h"
|
|
#include "EnhancedInputComponent.h"
|
|
#include "EnhancedInputSubsystems.h"
|
|
#include "Characters/ExoPlayerCharacter.h"
|
|
#include "GameFramework/Character.h"
|
|
#include "GameFramework/CharacterMovementComponent.h"
|
|
|
|
AExoPlayerController::AExoPlayerController()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
}
|
|
|
|
void AExoPlayerController::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
check(InputContext);
|
|
|
|
PlayerCharacter = Cast<AExoPlayerCharacter>(GetPawn<ACharacter>());
|
|
check(PlayerCharacter);
|
|
|
|
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
|
|
|
if (Subsystem)
|
|
{
|
|
Subsystem->AddMappingContext(InputContext, 0);
|
|
}
|
|
|
|
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
|
|
ShootingComponent = PlayerCharacter->FindComponentByClass<UShootingComponent>();
|
|
}
|
|
|
|
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);
|
|
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact);
|
|
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerJump);
|
|
EnhancedInputComponent->BindAction(DodgeAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerDodge);
|
|
//EnhancedInputComponent->BindAction(, ETriggerEvent::Started, this, &AExoPlayerController::ResetDodge);
|
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerCrouch);
|
|
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerSprint);
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
void AExoPlayerController::Interact()
|
|
{
|
|
if (InteractionComponent->InteractedActor)
|
|
IInteractable::Execute_Interact(InteractionComponent->InteractedActor);
|
|
}
|
|
|
|
void AExoPlayerController::PlayerJump()
|
|
{
|
|
|
|
}
|
|
|
|
void AExoPlayerController::PlayerDodge()
|
|
{
|
|
UE_LOG(LogTemp, Error, TEXT("Player Dodge"));
|
|
|
|
if (PlayerCharacter->GetCharacterMovement()->IsFalling()) return;
|
|
|
|
if (!CanDodge) return;
|
|
|
|
CanDodge = false;
|
|
|
|
FVector DodgeDirection = PlayerCharacter->GetVelocity().GetSafeNormal();
|
|
DodgeDirection.Z = 0.f;
|
|
|
|
if (DodgeDirection.IsNearlyZero())
|
|
DodgeDirection = PlayerCharacter->GetActorForwardVector();
|
|
|
|
PlayerCharacter->LaunchCharacter(DodgeDirection * DodgeForce, true, true);
|
|
|
|
GetWorldTimerManager().SetTimer(DodgeCooldownTimer, this, &AExoPlayerController::ResetDodge, DodgeCooldown, false);
|
|
}
|
|
|
|
void AExoPlayerController::ResetDodge()
|
|
{
|
|
CanDodge = true;
|
|
}
|
|
|
|
void AExoPlayerController::PlayerCrouch()
|
|
{
|
|
|
|
}
|
|
|
|
void AExoPlayerController::PlayerSprint()
|
|
{
|
|
|
|
}
|
|
|
|
void AExoPlayerController::PlayerShoot()
|
|
{
|
|
ShootingComponent->Shoot();
|
|
}
|
|
|
|
void AExoPlayerController::PlayerAim()
|
|
{
|
|
|
|
}
|
|
|
|
void AExoPlayerController::PlayerMeleAttack()
|
|
{
|
|
|
|
}
|
|
|
|
void AExoPlayerController::PlayerChangeWeapon()
|
|
{
|
|
|
|
}
|
|
|
|
void AExoPlayerController::PlayerReload()
|
|
{
|
|
|
|
}
|