此为ue课程Unreal Engine 5 C++ The Ultimate Game Developer Course第9节的笔记
87、the animation blueprint
使动作能够循环
动画事件蓝图
状态机设置
条件设置
动画设置
88、the anim instance
创建动画蓝图c++类
删掉原本的事件蓝图
将继承的类改为c++类
------------SlashAnimInstance.h-----------
#include "CoreMinimal.h"
#include "Animation/AnimInstance.h"
#include "SlashAnimInstance.generated.h"
/**
*
*/
UCLASS()
class MYPROJECT_API USlashAnimInstance : public UAnimInstance
{
GENERATED_BODY()
public:
virtual void NativeInitializeAnimation() override;
virtual void NativeUpdateAnimation(float DeltaTime) override;
UPROPERTY(BlueprintReadOnly)
class ASlashCharacter* SlashCharacter;
UPROPERTY(BlueprintReadOnly, Category = Movement)
class UCharacterMovementComponent* SlashCharacterMovement;
UPROPERTY(BlueprintReadOnly, Category = Movement)
float GroundSpeed;
};
-------------SlashAnimInstance.cpp-------------
#include "Characters/SlashAnimInstance.h"
#include "Characters/SlashCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Kismet/KismetMathLibrary.h"
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);
}
}
每一次按ctrl +f5时,game mode都会被重置,可以将当前的关卡另存为其他关卡保存gamemode设置
89、jumping
------------SlashCharacter.cpp-------------
void ASlashCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(FName("MoveForward"), this, &ASlashCharacter::MoveForward);
PlayerInputComponent->BindAxis(FName("Turn"), this, &ASlashCharacter::Turn);
PlayerInputComponent->BindAxis(FName("LookUp"), this, &ASlashCharacter::LookUp);
PlayerInputComponent->BindAxis(FName("MoveRight"), this, &ASlashCharacter::MoveRight);
PlayerInputComponent->BindAction(FName("Jump"), IE_Pressed, this, &ACharacter::Jump);
}
90、jump animation
----------SlashAnimInstance.h---------
UPROPERTY(BlueprintReadOnly, Category = Movement)
bool IsFalling;
-----------SlashAnimInstance.cpp--------------
void USlashAnimInstance::NativeUpdateAnimation(float DeltaTime)
{
Super::NativeUpdateAnimation(DeltaTime);
if (SlashCharacterMovement)
{
GroundSpeed = UKismetMathLibrary::VSizeXY(SlashCharacterMovement->Velocity);
IsFalling = SlashCharacterMovement->IsFalling();
}
}
蓝图部分
91、inverse kinematics
碰到add选项没有add vector函数时,使用add节点,然后右键转换为vector
、
如果没有内置IK,就创建virtual bone来使用
这一节课里面的函数没怎么听懂
创建foottrace函数
修改ABP_Echo
实现效果为让人物在静止时脚部能够做到与斜面对齐