跳转至

9 Animation

078 The Animation Blueprint

基于 Echo_Skeleton 创建动画蓝图 ABP_Echo

Img 1
Img 2
Img 3

Img 4

Img 5

Img 6

Img 7

079 The Anim Instance

基于 AnimInstance 创建一个 C++ 文件 SlashAnimInstance

SlashAnimInstance.h
class SLASH_API USlashAnimInstance : public UAnimInstance
{
    GENERATED_BODY()

public:
    virtual void NativeInitializeAnimation() override;
    virtual void NativeUpdateAnimation(float DeltaTime) override;

    UPROPERTY(BlueprintReadOnly)
    TObjectPtr<ASlashCharacter> SlashCharacter;
    UPROPERTY(BlueprintReadOnly, Category = "CMovement")
    TObjectPtr<UCharacterMovementComponent> SlashCharacterMovement;
    UPROPERTY(BlueprintReadOnly, Category = "CMovement")
    float GroundSpeed;
};
SlashAnimInstance.cpp
void USlashAnimInstance::NativeInitializeAnimation()
{
    Super::NativeInitializeAnimation();

    SlashCharacter = Cast<ASlashCharacter>(TryGetPawnOwner());
    if (SlashCharacter)
    {
        SlashCharacterMovement = SlashCharacter->GetCharacterMovement();
    }
}

void USlashAnimInstance::NativeUpdateAnimation(float DeltaTime)
{
    Super::NativeUpdateAnimation(DeltaTime);

    if (SlashCharacterMovement)
    {
        GroundSpeed = UKismetMathLibrary::VSizeXY(SlashCharacterMovement->Velocity);
    }
}

090 Jumping

SlashCharacter.h
1
2
3
4
5
6
7
8
class SLASH_API ASlashCharacter : public ACharacter
{
protected:
    UPROPERTY(EditDefaultsOnly, Category = "CInput")
    TObjectPtr<UInputAction> JumpAction;

    void Jump(const FInputActionValue& Value);
};
SlashCharacter.cpp
void ASlashCharacter::Jump(const FInputActionValue& Value)
{
    ACharacter::Jump();
}

void ASlashCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);

    if (UEnhancedInputComponent* EnhancedInputComponent= CastChecked<UEnhancedInputComponent>(PlayerInputComponent))
    {
        EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ASlashCharacter::Jump);
    }
}

091 Jump Animations

SlashAnimInstance.h
1
2
3
4
5
6
class SLASH_API USlashAnimInstance : public UAnimInstance
{
public:
    UPROPERTY(BlueprintReadOnly, Category = "CMovement")
    bool bIsFalling;
};
SlashAnimInstance.cpp
void USlashAnimInstance::NativeUpdateAnimation(float DeltaTime)
{
    Super::NativeUpdateAnimation(DeltaTime);

    if (SlashCharacterMovement)
    {
        GroundSpeed = UKismetMathLibrary::VSizeXY(SlashCharacterMovement->Velocity);
        bIsFalling = SlashCharacterMovement->IsFalling();
    }
}
Img 8
Img 9

Img 10

Img 11

Img 12

Img 13

Img 14

其中一个勾选基于状态中序列播放器的自动规则

另外一个

Img 15

082 Inverse Kinematics

基于 ControlRig 创建控制绑定文件

创建函数 FootTrace

Img 16
Img 17
Img 18
Img 19
Img 20
Img 21
Img 22
Img 23

评论区

欢迎在评论区指出文档错误,为文档提供宝贵意见,或写下你的疑问