diff --git a/Content/D2Contents/Blueprints/BP_D2BaseCharacter.uasset b/Content/D2Contents/Blueprints/BP_D2BaseCharacter.uasset new file mode 100644 index 0000000..ca2c9fb Binary files /dev/null and b/Content/D2Contents/Blueprints/BP_D2BaseCharacter.uasset differ diff --git a/Content/D2Contents/Blueprints/BP_D2Gamemode.uasset b/Content/D2Contents/Blueprints/BP_D2Gamemode.uasset new file mode 100644 index 0000000..9f7f68f Binary files /dev/null and b/Content/D2Contents/Blueprints/BP_D2Gamemode.uasset differ diff --git a/Content/Input/Actions/IA_Look.uasset b/Content/Input/Actions/IA_Look.uasset new file mode 100644 index 0000000..9dffd59 Binary files /dev/null and b/Content/Input/Actions/IA_Look.uasset differ diff --git a/Content/Input/Actions/IA_Move.uasset b/Content/Input/Actions/IA_Move.uasset new file mode 100644 index 0000000..e52af18 Binary files /dev/null and b/Content/Input/Actions/IA_Move.uasset differ diff --git a/Content/Input/IMC_Player.uasset b/Content/Input/IMC_Player.uasset new file mode 100644 index 0000000..fe3b937 Binary files /dev/null and b/Content/Input/IMC_Player.uasset differ diff --git a/Content/Maps/GameStartupMap.umap b/Content/Maps/GameStartupMap.umap index d8b4fb6..e98380b 100644 Binary files a/Content/Maps/GameStartupMap.umap and b/Content/Maps/GameStartupMap.umap differ diff --git a/Content/Maps/Lobby.umap b/Content/Maps/Lobby.umap index dc90c28..873b37b 100644 Binary files a/Content/Maps/Lobby.umap and b/Content/Maps/Lobby.umap differ diff --git a/D2.uproject b/D2.uproject index a089f68..c22ba68 100644 --- a/D2.uproject +++ b/D2.uproject @@ -7,7 +7,10 @@ { "Name": "D2", "Type": "Runtime", - "LoadingPhase": "Default" + "LoadingPhase": "Default", + "AdditionalDependencies": [ + "Engine" + ] } ], "Plugins": [ diff --git a/Source/D2/Character/D2BaseCharacter.cpp b/Source/D2/Character/D2BaseCharacter.cpp new file mode 100644 index 0000000..82c89e5 --- /dev/null +++ b/Source/D2/Character/D2BaseCharacter.cpp @@ -0,0 +1,116 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Character/D2BaseCharacter.h" +#include "EnhancedInputComponent.h" +#include "EnhancedInputSubsystems.h" +#include "GameFramework/CharacterMovementComponent.h" +#include "Camera/CameraComponent.h" +#include "GameFramework/SpringArmComponent.h" +#include "Components/CapsuleComponent.h" +#include "Components/InputComponent.h" +#include "InputAction.h" + +AD2BaseCharacter::AD2BaseCharacter() +{ + PrimaryActorTick.bCanEverTick = true; + + GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); + + bUseControllerRotationPitch = false; + bUseControllerRotationYaw = false; + bUseControllerRotationRoll = false; + + GetCharacterMovement()->bOrientRotationToMovement = true; + GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); + + GetCharacterMovement()->MaxAcceleration = 1500.f; + GetCharacterMovement()->BrakingFrictionFactor = 1.f; + GetCharacterMovement()->bUseSeparateBrakingFriction = true; + GetCharacterMovement()->JumpZVelocity = 700.f; + GetCharacterMovement()->AirControl = 0.35f; + GetCharacterMovement()->MaxWalkSpeed = 500.f; + GetCharacterMovement()->MinAnalogWalkSpeed = 20.f; + GetCharacterMovement()->BrakingDecelerationWalking = 2000.f; + GetCharacterMovement()->GravityScale = 1.75f; + GetMesh()->SetRelativeLocationAndRotation(FVector(0.f, 0.f, -100.f), FRotator(0.f, -90.f, 0.f)); + + CameraBoom = CreateDefaultSubobject(TEXT("CameraBoom")); + CameraBoom->SetupAttachment(RootComponent); + CameraBoom->TargetArmLength = 400.0f; + CameraBoom->bUsePawnControlRotation = true; + + FollowCamera = CreateDefaultSubobject(TEXT("FollowCamera")); + FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); + FollowCamera->bUsePawnControlRotation = false; +} + +void AD2BaseCharacter::BeginPlay() +{ + Super::BeginPlay(); + + if (APlayerController* PlayerController = Cast(Controller)) + { + if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer())) + Subsystem->AddMappingContext(DefaultMappingContext, 0); + } +} + +void AD2BaseCharacter::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); +} + +void AD2BaseCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + + if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked(PlayerInputComponent)) + { + //Moving + EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AD2BaseCharacter::Move); + + //Looking + EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AD2BaseCharacter::Look); + + //Jumping + EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump); + EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping); + } +} + +void AD2BaseCharacter::Move(const FInputActionValue& Value) +{ + FVector2D MovementVector = Value.Get(); + + if (Controller != nullptr) + { + // find out which way is forward + const FRotator Rotation = Controller->GetControlRotation(); + const FRotator YawRotation(0, Rotation.Yaw, 0); + + // get forward vector + const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); + + // get right vector + const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); + + // add movement + AddMovementInput(ForwardDirection, MovementVector.Y); + AddMovementInput(RightDirection, MovementVector.X); + } +} + +void AD2BaseCharacter::Look(const FInputActionValue& Value) +{ + // input is a Vector2D + FVector2D LookAxisVector = Value.Get(); + + if (Controller != nullptr) + { + // add yaw and pitch input to controller + AddControllerYawInput(LookAxisVector.X); + AddControllerPitchInput(LookAxisVector.Y); + } +} + diff --git a/Source/D2/Character/D2BaseCharacter.h b/Source/D2/Character/D2BaseCharacter.h new file mode 100644 index 0000000..311c6b2 --- /dev/null +++ b/Source/D2/Character/D2BaseCharacter.h @@ -0,0 +1,52 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Character.h" +#include "InputActionValue.h" + +#include "D2BaseCharacter.generated.h" + +UCLASS() +class D2_API AD2BaseCharacter : public ACharacter +{ + GENERATED_BODY() + +public: + AD2BaseCharacter(); + +protected: + virtual void BeginPlay() override; + +public: + virtual void Tick(float DeltaTime) override; + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + +protected: + //Input Funcs + void Move(const FInputActionValue& Value); + void Look(const FInputActionValue& Value); + //void Jump(const FInputActionValue& Value); + +protected: + //Default Components and Input System + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) + class USpringArmComponent* CameraBoom; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) + class UCameraComponent* FollowCamera; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + class UInputMappingContext* DefaultMappingContext; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + class UInputAction* MoveAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + UInputAction* LookAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + UInputAction* JumpAction; + +}; diff --git a/Source/D2/D2.Build.cs b/Source/D2/D2.Build.cs index d534c05..24b878b 100644 --- a/Source/D2/D2.Build.cs +++ b/Source/D2/D2.Build.cs @@ -8,9 +8,14 @@ public class D2 : ModuleRules { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); - - PrivateDependencyModuleNames.AddRange(new string[] { }); + PublicDependencyModuleNames.AddRange(new string[] + { + "Core", "CoreUObject", "Engine", "InputCore", + "Slate", "SlateCore", "EnhancedInput" + }); + + PublicIncludePaths.AddRange(new string[] { "D2" }); + //PrivateDependencyModuleNames.AddRange(new string[] { }); // Uncomment if you are using Slate UI // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); diff --git a/Source/D2/D2GameModeBase.cpp b/Source/D2/D2GameModeBase.cpp index 9e2b19a..c1ecadb 100644 --- a/Source/D2/D2GameModeBase.cpp +++ b/Source/D2/D2GameModeBase.cpp @@ -3,3 +3,7 @@ #include "D2GameModeBase.h" +AD2GameModeBase::AD2GameModeBase() +{ + +} diff --git a/Source/D2/D2GameModeBase.h b/Source/D2/D2GameModeBase.h index 90232f1..ed13604 100644 --- a/Source/D2/D2GameModeBase.h +++ b/Source/D2/D2GameModeBase.h @@ -13,5 +13,7 @@ UCLASS() class D2_API AD2GameModeBase : public AGameModeBase { GENERATED_BODY() - + +public: + AD2GameModeBase(); };