프로그래밍/Unreal

[18]UE4 C++_tutorial 0

redjam0123 2017. 5. 17. 21:09

01.플레이어 입력 및 폰 조종

https://docs.unrealengine.com/latest/KOR/Programming/Tutorials/PlayerInput/index.html

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Fill out your copyright notice in the Description page of Project Settings.
 
#include "UE4_Tutorial.h"
#include "MyPawn.h"
 
 
// Sets default values
AMyPawn::AMyPawn()
{
     // Set this pawn to call Tick() every frame.  
    PrimaryActorTick.bCanEverTick = true;
    AutoPossessPlayer = EAutoReceiveInput::Player0;
    // Create a dummy root component we can attach things to.
    RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
    // Create a camera and a visible object
    UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));
    OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));
    // Attach our camera and visible object to our root component. Offset and rotate the camera.
    OurCamera->AttachTo(RootComponent);
    OurCamera->SetRelativeLocation(FVector(-250.0f, 0.0f, 250.0f));
    OurCamera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));
    OurVisibleComponent->AttachTo(RootComponent);
}
 
// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
    Super::BeginPlay();
    MoveVelocity = 200.0f;    
}
 
// Called every frame
void AMyPawn::Tick( float DeltaTime )
{
    Super::Tick( DeltaTime );
    float CurrentScale = OurVisibleComponent->GetComponentScale().X;
    if (!CurrentVelocity.IsZero()){
        if (bGrowing){
            //growing up secends
            CurrentScale = CurrentScale * 2.0f;
        }
        FVector NewLocation = GetActorLocation() + (CurrentVelocity*DeltaTime);
        SetActorLocation(NewLocation);
        if (DeltaTime >= DeltaTime + 1.0){
            MoveVelocity = 1000.0f;
        }
    }
    if (bGrowing){
        //growing up secends
        CurrentScale += DeltaTime;
    }
    else
    {
        CurrentScale -= (DeltaTime*0.5f);
    }
    CurrentScale = FMath::Clamp(CurrentScale, 1.0f, 2.0f);
    OurVisibleComponent->SetWorldScale3D(FVector(CurrentScale));
}
void AMyPawn::Move_XAxis(float AxisValue){
    //move at 100units per seconds forward or backward
    CurrentVelocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) * MoveVelocity;    
}
void AMyPawn::Move_YAxis(float AxisValue){
    //move at 100 units per seconds right or left
    CurrentVelocity.Y = FMath::Clamp(AxisValue, -1.0f, 1.0f) * MoveVelocity;    
}
 
void AMyPawn::StartGrowing(){
    bGrowing = true;
}
 
void AMyPawn::StopGrowing(){
    bGrowing = false;
}
 
// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
    Super::SetupPlayerInputComponent(InputComponent);
    //when "grow" key is pressed or released
    InputComponent->BindAction("Grow", IE_Pressed, this&AMyPawn::StartGrowing);
    InputComponent->BindAction("Grow", IE_Released, this&AMyPawn::StopGrowing);
    //respond every frame to the values of our two movement axes, "MoveX" and "MoveY"
    InputComponent->BindAxis("MoveX"this&AMyPawn::Move_XAxis);
    InputComponent->BindAxis("MoveY"this&AMyPawn::Move_YAxis);
}
 
cs

 

이동 중 space 누르면 한번에 사이즈 2배까지.

 

2.게임조종카메라

https://docs.unrealengine.com/latest/KOR/Programming/Tutorials/AutoCamera/index.html

카메라1에서 카메라2로 부드럽게 이동.