Add basic PlayerCharacter
This commit is contained in:
parent
90a0a4c515
commit
c6059578ac
|
@ -2,6 +2,8 @@
|
|||
|
||||
[/Script/EngineSettings.GameMapsSettings]
|
||||
GameDefaultMap=/Engine/Maps/Templates/OpenWorld
|
||||
GlobalDefaultGameMode=/Game/Gamemode/BP_DefaultGamemode.BP_DefaultGamemode_C
|
||||
GameInstanceClass=/Script/vampires.VampireGameInstance
|
||||
|
||||
[/Script/WindowsTargetPlatform.WindowsTargetSettings]
|
||||
DefaultGraphicsRHI=DefaultGraphicsRHI_DX12
|
||||
|
|
Binary file not shown.
Binary file not shown.
BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)
BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -3,3 +3,67 @@
|
|||
|
||||
#include "PlayerCharacter.h"
|
||||
|
||||
#include "VampirePlayerController.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "InputMappingContext.h"
|
||||
|
||||
APlayerCharacter::APlayerCharacter()
|
||||
{
|
||||
// Create Camera Boom
|
||||
CameraSpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArmComponent"));
|
||||
CameraSpringArmComponent->SetupAttachment(RootComponent);
|
||||
CameraSpringArmComponent->bDoCollisionTest = true;
|
||||
CameraSpringArmComponent->bUsePawnControlRotation = false;
|
||||
CameraSpringArmComponent->TargetArmLength = 1000;
|
||||
CameraSpringArmComponent->bEnableCameraLag = false;
|
||||
CameraSpringArmComponent->SocketOffset = { 0.0f, 0.0f, 0.0f };
|
||||
CameraSpringArmComponent->SetRelativeRotation({-90.0, 0.0f, 0.0f});
|
||||
|
||||
// Create Camera
|
||||
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera Component"));
|
||||
CameraComponent->SetupAttachment(CameraSpringArmComponent, USpringArmComponent::SocketName);
|
||||
CameraComponent->bUsePawnControlRotation = false;
|
||||
CameraComponent->SetProjectionMode(ECameraProjectionMode::Type::Orthographic);
|
||||
CameraComponent->SetOrthoWidth(4000.0f);
|
||||
}
|
||||
|
||||
void APlayerCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
|
||||
if (AVampirePlayerController* TankPlayerController = Cast<AVampirePlayerController>(GetController()))
|
||||
{
|
||||
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(TankPlayerController->GetLocalPlayer()))
|
||||
{
|
||||
if (!InputMappingContext.IsNull())
|
||||
{
|
||||
InputSystem->AddMappingContext(InputMappingContext.LoadSynchronous(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>(PlayerInputComponent))
|
||||
{
|
||||
if (MovementAction)
|
||||
{
|
||||
Input->BindAction(MovementAction, ETriggerEvent::Triggered, this, &APlayerCharacter::MovementCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
|
||||
{
|
||||
FVector2D vec2 = Instance.GetValue().Get<FVector2D>();
|
||||
|
||||
if (vec2.Size() != 0.0f)
|
||||
{
|
||||
AddMovementInput({0.0f,1.0f,0.0f}, vec2.Y);
|
||||
AddMovementInput({1.0f,0.0f,0.0f}, vec2.X);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,13 @@
|
|||
|
||||
#include "CoreMinimal.h"
|
||||
#include "VampireCharacter.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "PlayerCharacter.generated.h"
|
||||
|
||||
class UInputMappingContext;
|
||||
class UInputAction;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -14,4 +19,34 @@ class VAMPIRES_API APlayerCharacter : public AVampireCharacter
|
|||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
USpringArmComponent* CameraSpringArmComponent = nullptr;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UCameraComponent* CameraComponent = nullptr;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSoftObjectPtr<UInputMappingContext> InputMappingContext;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
UInputAction* MovementAction;
|
||||
|
||||
public:
|
||||
|
||||
APlayerCharacter();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
private:
|
||||
|
||||
UFUNCTION()
|
||||
void MovementCallback(const FInputActionInstance& Instance);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "VampireGameInstance.h"
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Engine/GameInstance.h"
|
||||
#include "VampireGameInstance.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API UVampireGameInstance : public UGameInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "VampireGameMode.h"
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameMode.h"
|
||||
#include "VampireGameMode.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API AVampireGameMode : public AGameMode
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
};
|
|
@ -0,0 +1,23 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class vampires : ModuleRules
|
||||
{
|
||||
public vampires(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
|
||||
// Uncomment if you are using online features
|
||||
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
|
||||
|
||||
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "vampires.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, vampires, "vampires" );
|
|
@ -0,0 +1,6 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
Loading…
Reference in New Issue