영어단어

AnimInstance Class 생성

AnimClass인스턴스 클래스를 생성해서 캐릭터의 상태에 따른 애니메이션 업데이트를 할 여러 변수들을 선언했다.

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Animation/AnimInstance.h"
#include "ShooterAnimInstance.generated.h"

/**
 * 
 */
UCLASS()
class SHOOTINGGAME_API UShooterAnimInstance : public UAnimInstance
{
	GENERATED_BODY()
	
public:
	UFUNCTION(BlueprintCallable)
	void UpdateAnimationProperties(float DeltaTime);

	virtual void NativeInitializeAnimation() override;

private:

	UPROPERTY(VisibleAnywhere,BlueprintReadOnly, Category = Movement , meta = (AllowPrivateAcces = "true"))
	class AShooterCharacter* ShooterCharacter;

	// The speed of the character
	UPROPERTY(VisibleAnywhere,BlueprintReadOnly,Category = Movement , meta = (AllowPrivateAcces = "true"))
	float Speed;

	// Whether or not ther character is in the air
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAcces = "true"))
	bool bIsInAir;

	// Whether or not the character is moving
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAcces = "true"))
	bool bIsAccelerating;
};

속성 업데이트

void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime)
{
	if (nullptr == ShooterCharacter)
	{
		ShooterCharacter = Cast<AShooterCharacter>(TryGetPawnOwner());
	}
	if (ShooterCharacter)
	{
		// Get the lateral Speed of the character from velocity
		FVector Velocity{ ShooterCharacter->GetVelocity() };
		Velocity.Z = 0;
		Speed = Velocity.Size();

		// Is the character in the air?
		bIsInAir = ShooterCharacter->GetCharacterMovement()->IsFalling();

		// Is the character accelerating?
		// 가속도를 구해서 만약 가속이 0이라면 캐릭터는 움직이지 않는다고 판별한다.
		if (0 < ShooterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size())
			bIsAccelerating = true;
		else
			bIsAccelerating = false;

	}

}