From 2b4d42c3d308b840d76ff0e7474791c8480120bb Mon Sep 17 00:00:00 2001 From: sschan99 Date: Sun, 10 Apr 2022 00:00:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=ED=81=B4=EB=A6=AD=ED=95=9C=20=EC=9C=84?= =?UTF-8?q?=EC=B9=98=EB=A1=9C=20=EC=BA=90=EB=A6=AD=ED=84=B0=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=EC=8B=9C=ED=82=A4=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=ED=95=98=EA=B8=B0=20|=20=EC=96=B8=EB=A6=AC?= =?UTF-8?q?=EC=96=BC=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Study/seungchan/UE4_23/ClickMoveCharacter.cpp | 60 ++++++++++++++++++ Study/seungchan/UE4_23/ClickMoveCharacter.h | 36 +++++++++++ .../UE4_23/ClickMovePlayerController.cpp | 62 +++++++++++++++++++ .../UE4_23/ClickMovePlayerController.h | 35 +++++++++++ Study/seungchan/UE4_23/UE4_23.Build.cs | 23 +++++++ Study/seungchan/UE4_23/UE4_23.cpp | 6 ++ Study/seungchan/UE4_23/UE4_23.h | 6 ++ Study/seungchan/UE4_23/UE4_23GameModeBase.cpp | 5 ++ Study/seungchan/UE4_23/UE4_23GameModeBase.h | 17 +++++ 9 files changed, 250 insertions(+) create mode 100644 Study/seungchan/UE4_23/ClickMoveCharacter.cpp create mode 100644 Study/seungchan/UE4_23/ClickMoveCharacter.h create mode 100644 Study/seungchan/UE4_23/ClickMovePlayerController.cpp create mode 100644 Study/seungchan/UE4_23/ClickMovePlayerController.h create mode 100644 Study/seungchan/UE4_23/UE4_23.Build.cs create mode 100644 Study/seungchan/UE4_23/UE4_23.cpp create mode 100644 Study/seungchan/UE4_23/UE4_23.h create mode 100644 Study/seungchan/UE4_23/UE4_23GameModeBase.cpp create mode 100644 Study/seungchan/UE4_23/UE4_23GameModeBase.h 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() + +}; From 73fb56b8f42c254fdbc3646bbaeb9c6394064b0c Mon Sep 17 00:00:00 2001 From: sschan99 Date: Sun, 10 Apr 2022 01:06:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=ED=83=91=EB=8B=A4=EC=9A=B4=20=EC=8A=88?= =?UTF-8?q?=ED=8C=85=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20|=20=EC=96=B8=EB=A6=AC=EC=96=BC=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Study/seungchan/UE4_24/TopdownCharacter.cpp | 59 +++++++++++++++++ Study/seungchan/UE4_24/TopdownCharacter.h | 34 ++++++++++ .../UE4_24/TopdownPlayerController.cpp | 64 +++++++++++++++++++ .../UE4_24/TopdownPlayerController.h | 32 ++++++++++ Study/seungchan/UE4_24/UE4_24.Build.cs | 23 +++++++ Study/seungchan/UE4_24/UE4_24.cpp | 6 ++ Study/seungchan/UE4_24/UE4_24.h | 6 ++ Study/seungchan/UE4_24/UE4_24GameModeBase.cpp | 5 ++ Study/seungchan/UE4_24/UE4_24GameModeBase.h | 17 +++++ 9 files changed, 246 insertions(+) create mode 100644 Study/seungchan/UE4_24/TopdownCharacter.cpp create mode 100644 Study/seungchan/UE4_24/TopdownCharacter.h create mode 100644 Study/seungchan/UE4_24/TopdownPlayerController.cpp create mode 100644 Study/seungchan/UE4_24/TopdownPlayerController.h create mode 100644 Study/seungchan/UE4_24/UE4_24.Build.cs create mode 100644 Study/seungchan/UE4_24/UE4_24.cpp create mode 100644 Study/seungchan/UE4_24/UE4_24.h create mode 100644 Study/seungchan/UE4_24/UE4_24GameModeBase.cpp create mode 100644 Study/seungchan/UE4_24/UE4_24GameModeBase.h 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() + +};