- Add ExoGameMode class - Add ExoCharacterBase class - Add ExoPlayerController with basic movement and camera controls - Add blueprints for ExoPlayerController and ExoGameMode
67 lines
1.9 KiB
C++
67 lines
1.9 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 "GameFramework/Character.h"
|
|
|
|
AExoPlayerController::AExoPlayerController()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
}
|
|
|
|
void AExoPlayerController::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
check(InputContext);
|
|
|
|
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
|
|
|
if (Subsystem)
|
|
{
|
|
Subsystem->AddMappingContext(InputContext, 0);
|
|
}
|
|
|
|
PlayerCharacter = GetPawn<ACharacter>();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|