diff --git a/Study/seungchan/UE4_23/ClickMoveCharacter.cpp b/Study/seungchan/UE4_23/ClickMoveCharacter.cpp new file mode 100644 index 0000000..bf58fc4 --- /dev/null +++ b/Study/seungchan/UE4_23/ClickMoveCharacter.cpp @@ -0,0 +1,60 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ClickMoveCharacter.h" +#include +#include +#include +#include + +// Sets default values +AClickMoveCharacter::AClickMoveCharacter() +{ + // 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; + PrimaryActorTick.bStartWithTickEnabled = true; + + GetCapsuleComponent()->InitCapsuleSize(42.0f, 96.0f); + + bUseControllerRotationPitch = false; + bUseControllerRotationYaw = false; + bUseControllerRotationRoll = false; + + GetCharacterMovement()->bOrientRotationToMovement = true; + GetCharacterMovement()->RotationRate = FRotator(0.0f, 640.0f, 0.0f); + GetCharacterMovement()->bConstrainToPlane = true; + GetCharacterMovement()->bSnapToPlaneAtStart = true; + + SpringArmComponent = CreateDefaultSubobject(TEXT("CameraSpringArm")); + SpringArmComponent->SetupAttachment(RootComponent); + SpringArmComponent->SetUsingAbsoluteRotation(true); + SpringArmComponent->TargetArmLength = 800.0f; + SpringArmComponent->SetRelativeRotation(FRotator(-60.0f, 45.0f, 0.0f)); + SpringArmComponent->bDoCollisionTest = false; + + CameraComponent = CreateDefaultSubobject(TEXT("Camera")); + CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName); + CameraComponent->bUsePawnControlRotation = false; +} + +// Called when the game starts or when spawned +void AClickMoveCharacter::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AClickMoveCharacter::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + +// Called to bind functionality to input +void AClickMoveCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + +} + diff --git a/Study/seungchan/UE4_23/ClickMoveCharacter.h b/Study/seungchan/UE4_23/ClickMoveCharacter.h new file mode 100644 index 0000000..688b478 --- /dev/null +++ b/Study/seungchan/UE4_23/ClickMoveCharacter.h @@ -0,0 +1,36 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Character.h" +#include "ClickMoveCharacter.generated.h" + +UCLASS() +class UE4_23_API AClickMoveCharacter : public ACharacter +{ + GENERATED_BODY() + +public: + // Sets default values for this character's properties + AClickMoveCharacter(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + // Called to bind functionality to input + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + +private: + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true")) + class UCameraComponent* CameraComponent; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true")) + class USpringArmComponent* SpringArmComponent; + +}; diff --git a/Study/seungchan/UE4_23/ClickMovePlayerController.cpp b/Study/seungchan/UE4_23/ClickMovePlayerController.cpp new file mode 100644 index 0000000..3c8b7ae --- /dev/null +++ b/Study/seungchan/UE4_23/ClickMovePlayerController.cpp @@ -0,0 +1,62 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ClickMovePlayerController.h" +#include + +AClickMovePlayerController::AClickMovePlayerController() +{ + bShowMouseCursor = true; +} + +void AClickMovePlayerController::SetupInputComponent() +{ + Super::SetupInputComponent(); + InputComponent->BindAction("LeftClick", IE_Pressed, this, &AClickMovePlayerController::InputLeftMouseButtonPressed); + InputComponent->BindAction("LeftClick", IE_Released, this, &AClickMovePlayerController::InputLeftMouseButtonReleased); +} + +void AClickMovePlayerController::PlayerTick(float DeltaTime) +{ + Super::PlayerTick(DeltaTime); + + if (bClickLeftMouse) + { + MoveToMouseCursor(); + } +} + +void AClickMovePlayerController::InputLeftMouseButtonPressed() +{ + bClickLeftMouse = true; +} + +void AClickMovePlayerController::InputLeftMouseButtonReleased() +{ + bClickLeftMouse = false; +} + +void AClickMovePlayerController::SetNewDestination(const FVector Destination) +{ + APawn* const MyPawn = GetPawn(); + + if (MyPawn) + { + float const Distance = FVector::Dist(Destination, MyPawn->GetActorLocation()); + if (Distance > 120.0f) + { + UAIBlueprintHelperLibrary::SimpleMoveToLocation(this, Destination); + } + } +} + +void AClickMovePlayerController::MoveToMouseCursor() +{ + FHitResult Hit; + GetHitResultUnderCursor(ECC_Visibility, false, Hit); + + if (Hit.bBlockingHit) + { + SetNewDestination(Hit.ImpactPoint); + } +} \ No newline at end of file diff --git a/Study/seungchan/UE4_23/ClickMovePlayerController.h b/Study/seungchan/UE4_23/ClickMovePlayerController.h new file mode 100644 index 0000000..afdf89e --- /dev/null +++ b/Study/seungchan/UE4_23/ClickMovePlayerController.h @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/PlayerController.h" +#include "ClickMovePlayerController.generated.h" + +/** + * + */ +UCLASS() +class UE4_23_API AClickMovePlayerController : public APlayerController +{ + GENERATED_BODY() + +public: + AClickMovePlayerController(); + +protected: + bool bClickLeftMouse; + + void InputLeftMouseButtonPressed(); + + void InputLeftMouseButtonReleased(); + + void SetNewDestination(const FVector Destination); + + void MoveToMouseCursor(); + + virtual void SetupInputComponent() override; + + virtual void PlayerTick(float DeltaTime) override; + +}; diff --git a/Study/seungchan/UE4_23/UE4_23.Build.cs b/Study/seungchan/UE4_23/UE4_23.Build.cs new file mode 100644 index 0000000..eb4ea64 --- /dev/null +++ b/Study/seungchan/UE4_23/UE4_23.Build.cs @@ -0,0 +1,23 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +using UnrealBuildTool; + +public class UE4_23 : ModuleRules +{ + public UE4_23(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "NavigationSystem", "AIModule" }); + + 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 + } +} diff --git a/Study/seungchan/UE4_23/UE4_23.cpp b/Study/seungchan/UE4_23/UE4_23.cpp new file mode 100644 index 0000000..dd5762e --- /dev/null +++ b/Study/seungchan/UE4_23/UE4_23.cpp @@ -0,0 +1,6 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "UE4_23.h" +#include "Modules/ModuleManager.h" + +IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, UE4_23, "UE4_23" ); diff --git a/Study/seungchan/UE4_23/UE4_23.h b/Study/seungchan/UE4_23/UE4_23.h new file mode 100644 index 0000000..677c8e2 --- /dev/null +++ b/Study/seungchan/UE4_23/UE4_23.h @@ -0,0 +1,6 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" + diff --git a/Study/seungchan/UE4_23/UE4_23GameModeBase.cpp b/Study/seungchan/UE4_23/UE4_23GameModeBase.cpp new file mode 100644 index 0000000..786e30a --- /dev/null +++ b/Study/seungchan/UE4_23/UE4_23GameModeBase.cpp @@ -0,0 +1,5 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + + +#include "UE4_23GameModeBase.h" + diff --git a/Study/seungchan/UE4_23/UE4_23GameModeBase.h b/Study/seungchan/UE4_23/UE4_23GameModeBase.h new file mode 100644 index 0000000..d20620e --- /dev/null +++ b/Study/seungchan/UE4_23/UE4_23GameModeBase.h @@ -0,0 +1,17 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameModeBase.h" +#include "UE4_23GameModeBase.generated.h" + +/** + * + */ +UCLASS() +class UE4_23_API AUE4_23GameModeBase : public AGameModeBase +{ + GENERATED_BODY() + +}; diff --git a/Study/seungchan/UE4_24/TopdownCharacter.cpp b/Study/seungchan/UE4_24/TopdownCharacter.cpp new file mode 100644 index 0000000..e627539 --- /dev/null +++ b/Study/seungchan/UE4_24/TopdownCharacter.cpp @@ -0,0 +1,59 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "TopdownCharacter.h" +#include +#include +#include +#include + +// Sets default values +ATopdownCharacter::ATopdownCharacter() +{ + // 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; + PrimaryActorTick.bStartWithTickEnabled = true; + + GetCapsuleComponent()->InitCapsuleSize(42.0f, 96.0f); + + bUseControllerRotationPitch = false; + bUseControllerRotationRoll = false; + bUseControllerRotationYaw = false; + + GetCharacterMovement()->bOrientRotationToMovement = false; + + SpringArmComponent = CreateDefaultSubobject(TEXT("CameraSpringArm")); + SpringArmComponent->SetupAttachment(RootComponent); + SpringArmComponent->bInheritPitch = false; + SpringArmComponent->bInheritRoll = false; + SpringArmComponent->bInheritYaw = false; + SpringArmComponent->TargetArmLength = 1200.0f; + SpringArmComponent->SetRelativeRotation(FRotator(-60.0f, 0.0f, 0.0f)); + SpringArmComponent->bDoCollisionTest = false; + + CameraComponent = CreateDefaultSubobject(TEXT("Camera")); + CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName); + CameraComponent->bUsePawnControlRotation = false; +} + +// Called when the game starts or when spawned +void ATopdownCharacter::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void ATopdownCharacter::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + +// Called to bind functionality to input +void ATopdownCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + +} + diff --git a/Study/seungchan/UE4_24/TopdownCharacter.h b/Study/seungchan/UE4_24/TopdownCharacter.h new file mode 100644 index 0000000..7211b96 --- /dev/null +++ b/Study/seungchan/UE4_24/TopdownCharacter.h @@ -0,0 +1,34 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Character.h" +#include "TopdownCharacter.generated.h" + +UCLASS() +class UE4_24_API ATopdownCharacter : public ACharacter +{ + GENERATED_BODY() + +public: + // Sets default values for this character's properties + ATopdownCharacter(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + // Called to bind functionality to input + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true")) + class UCameraComponent* CameraComponent; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true")) + class USpringArmComponent* SpringArmComponent; +}; diff --git a/Study/seungchan/UE4_24/TopdownPlayerController.cpp b/Study/seungchan/UE4_24/TopdownPlayerController.cpp new file mode 100644 index 0000000..9e86137 --- /dev/null +++ b/Study/seungchan/UE4_24/TopdownPlayerController.cpp @@ -0,0 +1,64 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "TopdownPlayerController.h" +#include + +ATopdownPlayerController::ATopdownPlayerController() +{ + bShowMouseCursor = true; +} + +void ATopdownPlayerController::SetupInputComponent() +{ + Super::SetupInputComponent(); + + InputComponent->BindAxis("MoveForward", this, &ATopdownPlayerController::MoveForward); + InputComponent->BindAxis("MoveRight", this, &ATopdownPlayerController::MoveRight); +} + +void ATopdownPlayerController::PlayerTick(float DeltaTime) +{ + Super::PlayerTick(DeltaTime); + + LookMouseCursor(); +} + +void ATopdownPlayerController::MoveForward(float AxisValue) +{ + APawn* const MyPawn = GetPawn(); + + if (MyPawn) + { + FVector Direction = FVector::ForwardVector; + MyPawn->AddMovementInput(Direction, AxisValue); + } +} + +void ATopdownPlayerController::MoveRight(float AxisValue) +{ + APawn* const MyPawn = GetPawn(); + + if (MyPawn) + { + FVector Direction = FVector::RightVector; + MyPawn->AddMovementInput(Direction, AxisValue); + } +} + +void ATopdownPlayerController::LookMouseCursor() +{ + FHitResult Hit; + GetHitResultUnderCursor(ECC_Visibility, false, Hit); + + if (Hit.bBlockingHit) + { + APawn* const MyPawn = GetPawn(); + if (MyPawn) + { + FRotator LookRotation = UKismetMathLibrary::FindLookAtRotation(MyPawn->GetActorLocation(), + FVector(Hit.Location.X, Hit.Location.Y, MyPawn->GetActorLocation().Z)); + MyPawn->SetActorRotation(LookRotation); + } + } +} \ No newline at end of file diff --git a/Study/seungchan/UE4_24/TopdownPlayerController.h b/Study/seungchan/UE4_24/TopdownPlayerController.h new file mode 100644 index 0000000..e57a752 --- /dev/null +++ b/Study/seungchan/UE4_24/TopdownPlayerController.h @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/PlayerController.h" +#include "TopdownPlayerController.generated.h" + +/** + * + */ +UCLASS() +class UE4_24_API ATopdownPlayerController : public APlayerController +{ + GENERATED_BODY() + +public: + ATopdownPlayerController(); + + virtual void SetupInputComponent() override; + + virtual void PlayerTick(float DeltaTime) override; + + UFUNCTION() + void MoveForward(float AxisValue); + + UFUNCTION() + void MoveRight(float AxisValue); + + UFUNCTION() + void LookMouseCursor(); +}; diff --git a/Study/seungchan/UE4_24/UE4_24.Build.cs b/Study/seungchan/UE4_24/UE4_24.Build.cs new file mode 100644 index 0000000..01b3be0 --- /dev/null +++ b/Study/seungchan/UE4_24/UE4_24.Build.cs @@ -0,0 +1,23 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +using UnrealBuildTool; + +public class UE4_24 : ModuleRules +{ + public UE4_24(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); + + 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 + } +} diff --git a/Study/seungchan/UE4_24/UE4_24.cpp b/Study/seungchan/UE4_24/UE4_24.cpp new file mode 100644 index 0000000..3b04bff --- /dev/null +++ b/Study/seungchan/UE4_24/UE4_24.cpp @@ -0,0 +1,6 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "UE4_24.h" +#include "Modules/ModuleManager.h" + +IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, UE4_24, "UE4_24" ); diff --git a/Study/seungchan/UE4_24/UE4_24.h b/Study/seungchan/UE4_24/UE4_24.h new file mode 100644 index 0000000..677c8e2 --- /dev/null +++ b/Study/seungchan/UE4_24/UE4_24.h @@ -0,0 +1,6 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" + diff --git a/Study/seungchan/UE4_24/UE4_24GameModeBase.cpp b/Study/seungchan/UE4_24/UE4_24GameModeBase.cpp new file mode 100644 index 0000000..ff1dc2b --- /dev/null +++ b/Study/seungchan/UE4_24/UE4_24GameModeBase.cpp @@ -0,0 +1,5 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + + +#include "UE4_24GameModeBase.h" + diff --git a/Study/seungchan/UE4_24/UE4_24GameModeBase.h b/Study/seungchan/UE4_24/UE4_24GameModeBase.h new file mode 100644 index 0000000..f9d3b42 --- /dev/null +++ b/Study/seungchan/UE4_24/UE4_24GameModeBase.h @@ -0,0 +1,17 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameModeBase.h" +#include "UE4_24GameModeBase.generated.h" + +/** + * + */ +UCLASS() +class UE4_24_API AUE4_24GameModeBase : public AGameModeBase +{ + GENERATED_BODY() + +};