언리얼 5

230831 애니메이션 스테이트 머신 / 지금까지 한거 블루프린트 대신 c++ 로 작업해보기

슬뷔 2023. 8. 31. 10:55

애니메이션 스테이트 머신 

캐시포즈

=> 결과물을 받아놓고 사용

why? 

ABP_Player -> AnimGraph -> Main

 

점프

=> 지면에 닿아있는지 아닌지 Move를 이용해서 구현

자연스러우려면 점프할 때, 점프하는 동작에 맞춰서 모션이 (웅크렸다가 착지하는?) 나와주어야한다.

BPC_Player
BPC_Player / ABP_Player -> AnimGraph -> Main
ABP_Player -> AnimGraph -> Main -> Idle/Move -> Jump

* 애니메이션 모션 합치기

 

 

추락

=> 점프와 다르게 

 

블랜드 세팅 ( 애니메이션 모드 전환 )

모드 -> cubic

경과 시간 -> 0.6

 

착지

 

BPC_Player -> 이벤트 그래프의 tick 이벤트


가만히 있거나 걷다가 갑자기 추락하는 경우 => 점프 모션이 나오면 안되고 바로  추락하는 모션이 나와야해서 따로 트랜지션을 만들어준다. 

 

* 위처럼 만들었더니 점프를 했는데 바로 추락하는 애니메이션이 나옴

해결방안 -> 디테일의 트랜지션에서 우선순위를 만들어줌


점프모션이 나오다가 갑자기 착지가 될 때도 있다 => 바로 착지 모션이 나와야함 

 


착지하고 있는데 점프키를 눌렀을 때


스테이트 에일리어스 ( UE 5 부터 추가 )

=> 특정 스테이트로 갈 수 있는 조건을 체크하는 역할

 

나중에 가면 스테이트 머신이 복잡해지니까 한 눈에 잘 보이지 않고 복잡해져서 간결하게 정리하고자 나온 것

 

ex)

Idle/Move -> Jump

Land -> Jump

진입 조건이 똑같다.

Jump -> Land

Fall -> Land

진입 조건이 똑같다.

갑자기 추락으로 빠지는 경우

 

점프 -> 추락 ( 자동조건 )

네모 박스를 체크한다.

 

에일리어스를 이용하여 이렇게 정리할 수 있다..

 


c++ 이용해서 점프, 스프린트토글, 로테이션 구현

Character_Base.h

UCLASS()
class UNREAL_3TH_API ACharacter_Base : public ACharacter
{
private:
	UPROPERTY(EditAnywhere, Category = "Input")
	TSoftObjectPtr<UInputAction>			JumpAction;

	UPROPERTY(EditAnywhere, Category = "Input")
	TSoftObjectPtr<UInputAction>			SprintToggleAction;

	UPROPERTY(EditAnywhere, Category = "Input")
	TSoftObjectPtr<UInputAction>			AttackAction;
}
Character_Base.cpp
// 컨트롤러가 빙의할때, 컨트롤러의 인풋 컴포넌트를 인자로 넣어주면서 빙의대상 액터에게 호출해주는 함수
void ACharacter_Base::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	if (!SprintToggleAction.IsNull())
	{
		InputCom->BindAction(SprintToggleAction.LoadSynchronous(), ETriggerEvent::Triggered, this, &ACharacter_Base::SprintToggle);
	}

	if (!JumpAction.IsNull())
	{
		InputCom->BindAction(JumpAction.LoadSynchronous(), ETriggerEvent::Triggered, this, &ACharacter_Base::Jump);
	}
}

void ACharacter_Base::Ratation(const FInputActionInstance& _Inatance)
{
	FVector2D vInput = _Inatance.GetValue().Get<FVector2D>();

	//Pitch, Yaw, Roll
	AddControllerYawInput(vInput.X);

	float DT = GetWorld()->GetDeltaSeconds();

	FRotator rot = m_Arm->GetRelativeRotation();
	rot.Pitch += vInput.Y * 100.f * DT;

	if (rot.Pitch > 40.f)
		rot.Pitch = 40.f;

	else if (rot.Pitch < -40.f)
		rot.Pitch = -40.f;
	
	m_Arm->SetRelativeRotation(rot);
}

void ACharacter_Base::SprintToggle(const FInputActionInstance& _Inatance)
{
	bool bToggle = _Inatance.GetValue().Get<bool>();

	if(bToggle)
	{
		// shift 키가 눌렸을 때
		GetCharacterMovement()->MaxWalkSpeed = 600.f;
	}

	else
	{
		// shift 키가 눌리지 않았을 때 
		GetCharacterMovement()->MaxWalkSpeed = 300.f;
	}
}

void ACharacter_Base::Jump(const FInputActionInstance& _Inatance)
{
	// 부모에 구현되어 있음
	Super::Jump();
}

 

'언리얼 5' 카테고리의 다른 글

230904  (0) 2023.09.04
230901  (0) 2023.09.01
230830 회전 블루프린트 / 애니메이션  (0) 2023.08.30
230829 캐릭터 이동 및 카메라 회전  (0) 2023.08.29
230828 언리얼 엔진 5.1.1 시작  (0) 2023.08.28