Test Character and controller
This commit is contained in:
5
Source/OpenConflict/Private/MyGameModeBase.cpp
Normal file
5
Source/OpenConflict/Private/MyGameModeBase.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "MyGameModeBase.h"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "MyPlayerCharacter/MyCharacter.h"
|
||||
|
||||
// Sets default values
|
||||
AMyCharacter::AMyCharacter()
|
||||
{
|
||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
||||
CameraComponent->SetupAttachment(RootComponent);
|
||||
CameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f));
|
||||
CameraComponent->bUsePawnControlRotation = true;
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void AMyCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "MyPlayerCharacter/MyPlayerController.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "Components/SplineMeshComponent.h"
|
||||
|
||||
AMyPlayerController::AMyPlayerController()
|
||||
{
|
||||
}
|
||||
|
||||
void AMyPlayerController::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
PlayerCharacter = Cast<AMyCharacter>(GetCharacter());
|
||||
|
||||
if (AMyPlayerController* PC = Cast<AMyPlayerController>(this))
|
||||
{
|
||||
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()))
|
||||
{
|
||||
if(PlayerInputContext)
|
||||
{
|
||||
Subsystem->AddMappingContext(PlayerInputContext, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AMyPlayerController::SetupInputComponent()
|
||||
{
|
||||
Super::SetupInputComponent();
|
||||
if (AMyPlayerController* PC = Cast<AMyPlayerController>(this))
|
||||
{
|
||||
if (UEnhancedInputComponent* Subsystem = Cast<UEnhancedInputComponent>(InputComponent))
|
||||
{
|
||||
if (MoveAction)
|
||||
{
|
||||
Subsystem->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AMyPlayerController::Move);
|
||||
}
|
||||
if (JumpAction)
|
||||
{
|
||||
Subsystem->BindAction(JumpAction, ETriggerEvent::Started, this, &AMyPlayerController::Jump);
|
||||
}
|
||||
if (LookAction)
|
||||
{
|
||||
Subsystem->BindAction(LookAction, ETriggerEvent::Triggered, this, &AMyPlayerController::Look);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AMyPlayerController::Move(const FInputActionValue& Value)
|
||||
{
|
||||
FVector2D MovementVector = Value.Get<FVector2D>();
|
||||
|
||||
if (APawn* ControlledPawn = GetPawn())
|
||||
{
|
||||
FRotator CameraRotation = GetControlRotation();
|
||||
FRotator YawRotation(0.f, CameraRotation.Yaw, 0.f);
|
||||
|
||||
FVector ForwardDiection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
||||
FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
||||
|
||||
ControlledPawn->AddMovementInput(ForwardDiection, MovementVector.Y);
|
||||
ControlledPawn->AddMovementInput(RightDirection,MovementVector.X);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void AMyPlayerController::Look(const FInputActionValue& Value)
|
||||
{
|
||||
FVector2D LookAxisVector = Value.Get<FVector2D>();
|
||||
|
||||
if (APawn* ControlledPawn = GetPawn())
|
||||
{
|
||||
AddYawInput(LookAxisVector.X);
|
||||
AddPitchInput(LookAxisVector.Y);
|
||||
}
|
||||
}
|
||||
|
||||
void AMyPlayerController::Jump(const FInputActionValue& Value)
|
||||
{
|
||||
}
|
||||
|
||||
17
Source/OpenConflict/Public/MyGameModeBase.h
Normal file
17
Source/OpenConflict/Public/MyGameModeBase.h
Normal file
@@ -0,0 +1,17 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "MyGameModeBase.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class OPENCONFLICT_API AMyGameModeBase : public AGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
};
|
||||
28
Source/OpenConflict/Public/MyPlayerCharacter/MyCharacter.h
Normal file
28
Source/OpenConflict/Public/MyPlayerCharacter/MyCharacter.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "MyCharacter.generated.h"
|
||||
|
||||
|
||||
UCLASS()
|
||||
class OPENCONFLICT_API AMyCharacter : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this character's properties
|
||||
AMyCharacter();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera")
|
||||
UCameraComponent* CameraComponent;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "MyCharacter.h"
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "MyPlayerController.generated.h"
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class OPENCONFLICT_API AMyPlayerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
AMyPlayerController();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Input")
|
||||
UInputMappingContext* PlayerInputContext;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Input")
|
||||
UInputAction* MoveAction;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Input")
|
||||
UInputAction* LookAction;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Input")
|
||||
UInputAction* JumpAction;
|
||||
|
||||
public:
|
||||
virtual void SetupInputComponent() override;
|
||||
|
||||
UPROPERTY()
|
||||
AMyCharacter* PlayerCharacter;
|
||||
|
||||
private:
|
||||
void Move(const FInputActionValue& Value);
|
||||
void Look(const FInputActionValue& Value);
|
||||
void Jump(const FInputActionValue& Value);
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user