Section 02

UE5
Aura
Udemy
Game
Programming
Author

Serika Yuzuki

Published

October 9, 2023

Sec 02 について

流れ

  1. まずRiderで作業するのに集中するために、Auto CompileやLive Codingを消した。
  2. キャラクターの基本のセットアップ
    1. Created Character Class
    2. Created Weapon object and attached to mesh
    3. Applied Animation
  3. Setting up player enhanced input
    1. Private Dependency Module にEnhanced Inputを入れないといけない
  4. Setup GameModeBase and GameBase
    1. Setup PlayerController
    2. Casting input to enhanced input
    3. Setup Move function
  5. highlight the enemy when mouse over
    1. by creating interface
    2. Highlighting via post process material
      1. add post process volume and make it extens infinite
      2. custom depth stencil : Enabled with Stencil
      3. add PP_highlighing material to post process volume
      4. change enemy actor’s custom depth

発見

BindActionの第4引数に渡す関数ポインタの型をドキュメントで知りたい

void AAuraPlayerController::SetupInputComponent()
{
    ...
    EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
}

void AAuraPlayerController::Move(const FInputActionValue& Value) {...}

BindActionの第4引数には、void (AAuraPlayerController::*)(const FInputActionValue&) という型の関数ポインタを渡す必要がある。これはどこを読めばわかるのか?

BindActionのドキュメントによれば、上の関数の引数の形は

template<class UserClass>
FInputActionBinding & BindAction
(
    const FName ActionName,
    const EInputEvent KeyEvent,
    UserClass * Object,
    typename FInputActionHandlerWithKeySignature::TMethodPtr< UserClass > Func
)

で、この第四引数であるFEnhancedInputActionHandlerValueSignatureドキュメントによれば、 typedef TBaseDelegate_OneParam< void, const FInputActionValue & > FEnhancedInputActionHandlerValueSignature

Rotation MatrixのGetUnitAxisの意味

const FVector2D InputAxisVector = Value.Get<FVector2D>();
const FRotator Rotation = GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);

const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

if (APawn* ContrlledPawn = GetPawn<APawn>())
{
    ContrlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y);
    ContrlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
}

FRotationMatrix(YawRotation) は、YawRotationを回転行列に変換している。この回転行列は、YawRotationの回転軸をZ軸にしている。ここまではいいが、行列にする意味は何か?

GetUnitAxis(EAxis::X) は、回転行列の1列目を取得していることになる。

\[ \begin{pmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{pmatrix} \longmapsto \begin{pmatrix} \cos\theta \\ \sin\theta \\ 0 \end{pmatrix} , \begin{pmatrix} -\sin\theta \\ \cos\theta \\ 0 \end{pmatrix} , \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} \]

これについて考えれば、1,2,3列目のベクトルとは、回転後のベクトルの、向いている方向、その方向を \(x'\) 軸として作り上げる右手系 \(x', y', z'\) の基底ベクトルになっていることがわかる。

GetControlRotation()でControl世界の回転を取得しているので、その世界の \(x, y\) 軸への方向に動きを制限して、Inputを適用している。

仮想関数周り

class Parent{
public:
    virtual void VFunc() { std::cout << "Parent" << std::endl; }
    void NVFunc() { std::cout << "Parent" << std::endl; }
};

class Child : public Parent{
public:
    void VFunc() override { std::cout << "Child" << std::endl; }
    void NVFunc() { std::cout << "Child" << std::endl; }
};

int main()
{
    Parent* p = new Child();
    // Parentとしてpを定義しているので、virtualじゃない関数はParentのものが呼ばれる
    p->VFunc(); // Child
    // virtualな関数はChildのものが呼ばれる
    p->NVFunc(); // Parent
}

以上がvirtualについての話で、sub classで書き換えられる前提の関数は次のように書く。

class Parent{
public:
    virtual void VFunc() = 0;
};

Tick関連の話

PrimaryActorTick.bCanEverTick = true;

これをContructorで設定しないとTickしない。ただし、PlayerControllerはデフォルトでPlayerTickするようになっている。

Collision Channelの話

Character Collision PresetではECC_VisibilityがOffになってるんで気をつけて。

Back to top