Space Plunder
Loading...
Searching...
No Matches
ATP_ThirdPersonCharacter Class Reference

#include <TP_ThirdPersonCharacter.h>

Inheritance diagram for ATP_ThirdPersonCharacter:

Public Member Functions

 ATP_ThirdPersonCharacter ()
 
FORCEINLINE class USpringArmComponent * GetCameraBoom () const
 
FORCEINLINE class UCameraComponent * GetFollowCamera () const
 

Protected Member Functions

void Move (const FInputActionValue &Value)
 
void Look (const FInputActionValue &Value)
 
virtual void SetupPlayerInputComponent (class UInputComponent *PlayerInputComponent) override
 
virtual void BeginPlay ()
 

Private Attributes

class USpringArmComponent * CameraBoom
 
class UCameraComponent * FollowCamera
 
class UInputMappingContext * DefaultMappingContext
 
class UInputAction * JumpAction
 
class UInputAction * MoveAction
 
class UInputAction * LookAction
 

Constructor & Destructor Documentation

◆ ATP_ThirdPersonCharacter()

ATP_ThirdPersonCharacter::ATP_ThirdPersonCharacter ( )
18{
19 // Set size for collision capsule
20 GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
21
22 // Don't rotate when the controller rotates. Let that just affect the camera.
23 bUseControllerRotationPitch = false;
24 bUseControllerRotationYaw = false;
25 bUseControllerRotationRoll = false;
26
27 // Configure character movement
28 GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...
29 GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate
30
31 // Note: For faster iteration times these variables, and many more, can be tweaked in the Character Blueprint
32 // instead of recompiling to adjust them
33 GetCharacterMovement()->JumpZVelocity = 700.f;
34 GetCharacterMovement()->AirControl = 0.35f;
35 GetCharacterMovement()->MaxWalkSpeed = 500.f;
36 GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
37 GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;
38
39 // Create a camera boom (pulls in towards the player if there is a collision)
40 CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
41 CameraBoom->SetupAttachment(RootComponent);
42 CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character
43 CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
44
45 // Create a follow camera
46 FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
47 FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
48 FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
49
50 // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
51 // are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
52}
class USpringArmComponent * CameraBoom
Definition TP_ThirdPersonCharacter.h:18
class UCameraComponent * FollowCamera
Definition TP_ThirdPersonCharacter.h:22

Member Function Documentation

◆ BeginPlay()

void ATP_ThirdPersonCharacter::BeginPlay ( )
protectedvirtual
55{
56 // Call the base class
57 Super::BeginPlay();
58
59 //Add Input Mapping Context
60 if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
61 {
62 if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
63 {
64 Subsystem->AddMappingContext(DefaultMappingContext, 0);
65 }
66 }
67}
class UInputMappingContext * DefaultMappingContext
Definition TP_ThirdPersonCharacter.h:26

◆ GetCameraBoom()

FORCEINLINE class USpringArmComponent * ATP_ThirdPersonCharacter::GetCameraBoom ( ) const
inline

Returns CameraBoom subobject

62{ return CameraBoom; }

◆ GetFollowCamera()

FORCEINLINE class UCameraComponent * ATP_ThirdPersonCharacter::GetFollowCamera ( ) const
inline

Returns FollowCamera subobject

64{ return FollowCamera; }

◆ Look()

void ATP_ThirdPersonCharacter::Look ( const FInputActionValue & Value)
protected

Called for looking input

115{
116 // input is a Vector2D
117 FVector2D LookAxisVector = Value.Get<FVector2D>();
118
119 if (Controller != nullptr)
120 {
121 // add yaw and pitch input to controller
122 AddControllerYawInput(LookAxisVector.X);
123 AddControllerPitchInput(LookAxisVector.Y);
124 }
125}

◆ Move()

void ATP_ThirdPersonCharacter::Move ( const FInputActionValue & Value)
protected

Called for movement input

92{
93 // input is a Vector2D
94 FVector2D MovementVector = Value.Get<FVector2D>();
95
96 if (Controller != nullptr)
97 {
98 // find out which way is forward
99 const FRotator Rotation = Controller->GetControlRotation();
100 const FRotator YawRotation(0, Rotation.Yaw, 0);
101
102 // get forward vector
103 const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
104
105 // get right vector
106 const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
107
108 // add movement
109 AddMovementInput(ForwardDirection, MovementVector.Y);
110 AddMovementInput(RightDirection, MovementVector.X);
111 }
112}

◆ SetupPlayerInputComponent()

void ATP_ThirdPersonCharacter::SetupPlayerInputComponent ( class UInputComponent * PlayerInputComponent)
overrideprotectedvirtual
73{
74 // Set up action bindings
75 if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) {
76
77 //Jumping
78 EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
79 EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
80
81 //Moving
82 EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ATP_ThirdPersonCharacter::Move);
83
84 //Looking
85 EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ATP_ThirdPersonCharacter::Look);
86
87 }
88
89}
class UInputAction * MoveAction
Definition TP_ThirdPersonCharacter.h:34
void Move(const FInputActionValue &Value)
Definition TP_ThirdPersonCharacter.cpp:91
void Look(const FInputActionValue &Value)
Definition TP_ThirdPersonCharacter.cpp:114
class UInputAction * JumpAction
Definition TP_ThirdPersonCharacter.h:30
class UInputAction * LookAction
Definition TP_ThirdPersonCharacter.h:38

Member Data Documentation

◆ CameraBoom

class USpringArmComponent* ATP_ThirdPersonCharacter::CameraBoom
private

Camera boom positioning the camera behind the character

◆ DefaultMappingContext

class UInputMappingContext* ATP_ThirdPersonCharacter::DefaultMappingContext
private

MappingContext

◆ FollowCamera

class UCameraComponent* ATP_ThirdPersonCharacter::FollowCamera
private

Follow camera

◆ JumpAction

class UInputAction* ATP_ThirdPersonCharacter::JumpAction
private

Jump Input Action

◆ LookAction

class UInputAction* ATP_ThirdPersonCharacter::LookAction
private

Look Input Action

◆ MoveAction

class UInputAction* ATP_ThirdPersonCharacter::MoveAction
private

Move Input Action


The documentation for this class was generated from the following files: