Repository navigation
Expand file tree
/
Copy pathFlyingCamera.cpp
More file actions
69 lines (56 loc) · 1.92 KB
/
Copy pathFlyingCamera.cpp
File metadata and controls
69 lines (56 loc) · 1.92 KB
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
// Fill out your copyright notice in the Description page of Project Settings.
#include "FlyingCamera.h"
AFlyingCamera::AFlyingCamera()
{
PrimaryActorTick.bCanEverTick = true;
Camera = CreateDefaultSubobject<UCameraComponent>("Camera");
Camera->SetupAttachment(RootComponent);
}
void AFlyingCamera::BeginPlay()
{
Super::BeginPlay();
SetActorLocation(FVector(-600, 600, 1500));
SetActorRotation(FRotator(-15, 5, 0));
}
void AFlyingCamera::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
CurrentDeltaTime = DeltaTime;
}
void AFlyingCamera::SetupPlayerInputComponent(
UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
InputComponent->BindAxis("VerticalAxis", this,
&AFlyingCamera::MoveVertically);
InputComponent->BindAxis("HorizontalAxis", this,
&AFlyingCamera::MoveHorizontally);
InputComponent->BindAxis("MouseX", this, &AFlyingCamera::RotateYaw);
InputComponent->BindAxis("MouseY", this, &AFlyingCamera::RotatePitch);
}
void AFlyingCamera::MoveVertically(float Value)
{
FQuat Rotation = GetActorRotation().Quaternion();
FVector Direction =
Rotation * FVector(1, 0, 0) * Value * MoveSpeed * CurrentDeltaTime;
SetActorLocation(GetActorLocation() + Direction);
}
void AFlyingCamera::MoveHorizontally(float Value)
{
FQuat Rotation = GetActorRotation().Quaternion();
FVector Direction =
Rotation * FVector(0, 1, 0) * Value * MoveSpeed * CurrentDeltaTime;
SetActorLocation(GetActorLocation() + Direction);
}
void AFlyingCamera::RotateYaw(float Value)
{
FRotator NewRotation = GetActorRotation();
NewRotation.Yaw = NewRotation.Yaw + Value;
SetActorRotation(NewRotation);
}
void AFlyingCamera::RotatePitch(float Value)
{
FRotator NewRotation = GetActorRotation();
NewRotation.Pitch = FMath::Clamp(NewRotation.Pitch + Value, -80.0f, 80.0f);
SetActorRotation(NewRotation);
}