Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Study/seungchan/UE4_23/ClickMoveCharacter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "ClickMoveCharacter.h"
#include <Engine/Classes/Components/CapsuleComponent.h>
#include <Engine/Classes/Camera/CameraComponent.h>
#include <Engine/Classes/GameFramework/CharacterMovementComponent.h>
#include <Engine/Classes/GameFramework/SpringArmComponent.h>

// 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<USpringArmComponent>(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<UCameraComponent>(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);

}

36 changes: 36 additions & 0 deletions Study/seungchan/UE4_23/ClickMoveCharacter.h
Original file line number Diff line number Diff line change
@@ -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;

};
62 changes: 62 additions & 0 deletions Study/seungchan/UE4_23/ClickMovePlayerController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "ClickMovePlayerController.h"
#include <Blueprint/AIBlueprintHelperLibrary.h>

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);
}
}
35 changes: 35 additions & 0 deletions Study/seungchan/UE4_23/ClickMovePlayerController.h
Original file line number Diff line number Diff line change
@@ -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;

};
23 changes: 23 additions & 0 deletions Study/seungchan/UE4_23/UE4_23.Build.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 6 additions & 0 deletions Study/seungchan/UE4_23/UE4_23.cpp
Original file line number Diff line number Diff line change
@@ -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" );
6 changes: 6 additions & 0 deletions Study/seungchan/UE4_23/UE4_23.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

5 changes: 5 additions & 0 deletions Study/seungchan/UE4_23/UE4_23GameModeBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright Epic Games, Inc. All Rights Reserved.


#include "UE4_23GameModeBase.h"

17 changes: 17 additions & 0 deletions Study/seungchan/UE4_23/UE4_23GameModeBase.h
Original file line number Diff line number Diff line change
@@ -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()

};
59 changes: 59 additions & 0 deletions Study/seungchan/UE4_24/TopdownCharacter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "TopdownCharacter.h"
#include <Engine/Classes/Components/CapsuleComponent.h>
#include <Engine/Classes/Camera/CameraComponent.h>
#include <Engine/Classes/GameFramework/CharacterMovementComponent.h>
#include <Engine/Classes/GameFramework/SpringArmComponent.h>

// 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<USpringArmComponent>(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<UCameraComponent>(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);

}

34 changes: 34 additions & 0 deletions Study/seungchan/UE4_24/TopdownCharacter.h
Original file line number Diff line number Diff line change
@@ -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;
};
Loading