播放动作
UBlendSpace1D *pBlendSpace = LoadObject<UBlendSpace1D>(nullptr, *montageName);
UAnimInstance *pAnimInstance = GetMesh()->GetAnimInstance();
if (pBlendSpace && pAnimInstance) {
bUpdateSpeed = true;
GetMesh()->PlayAnimation(pBlendSpace, true);
FVector BlendParams(GetVelocity().Size(), 0.f, 0.f);
GetMesh()->GetSingleNodeInstance()->SetBlendSpaceInput(BlendParams);
}
这里的blendSpace 的param类型是FVector, 在BlendSpace1D中,我们只用到了X轴方向的参数:
image.png
所以只设置x就可以了
还需要毎帧设置速度:
void AAnimCppCharacter::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (bUpdateSpeed) {
FVector BlendParams(GetVelocity().Size(), 0.f, 0.f);
GetMesh()->GetSingleNodeInstance()->SetBlendSpaceInput(BlendParams);
}
}
网友评论