You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity 3D RPG开发中Blender导入动画失效问题求助

Blender导出FBX动画在Unity RPG项目中无法正常运行

问题背景

正在跟随Sebastian Lague和Brackeys的教程制作Unity 3D RPG游戏,但从Blender导出的FBX动画无法正常运行。已反复检查动画及Blender导入设置,导入格式为FBX。

Animator截图

Animator状态机截图1
Animator参数与过渡截图2

相关C#代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class CharacterAnimator : MonoBehaviour
{   
    const float locomotionAnimationSmoothTime = .1f;

    NavMeshAgent agent;
    Animator animator;

    // Start is called before the first frame update
    void Start()
    {
        agent = GetComponent<NavMeshAgent>();
        animator = GetComponentInChildren<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        float speedPercent = animator.velocity.magnitude / agent.speed;
        
        animator.SetFloat("speedPercent", speedPercent, locomotionAnimationSmoothTime, Time.deltaTime);
    }
}

排查与解决建议

1. 代码逻辑修正

当前代码用animator.velocity.magnitude计算速度占比是错误的——Animator的velocity是动画自身的播放速度,不是角色实际移动速度。应该替换为NavMeshAgent的真实移动速度:

float speedPercent = agent.velocity.magnitude / agent.speed;

2. Animator状态机检查

从截图确认以下几点:

  • 动画过渡条件阈值合理:比如Idle转Walk的条件设为speedPercent > 0.1(阈值别太高,避免轻微移动不触发),反向过渡设为speedPercent < 0.1
  • 动画片段的Speed属性未被误设为0
  • 关闭Animator组件的Apply Root Motion选项:用NavMeshAgent控制移动时,让NavMeshAgent负责位移,Animator只播放动画

3. Blender导出与Unity导入设置核对

  • Blender导出FBX时,务必勾选Bake Animation,确保所有关键帧被正确烘焙
  • Unity导入FBX的Rig标签下,Animation Type选Humanoid(人形角色),点击Configure确认Avatar映射无红叉
  • 导入的Animation标签下,确认目标动画片段已正确拆分,循环动画需勾选Loop Time

4. 组件挂载与层级验证

  • 确认CharacterAnimator脚本挂载在带NavMeshAgent的根对象上,Animator组件在子骨骼对象上,GetComponentInChildren<Animator>()能正确获取到组件
  • 检查NavMesh是否已正确烘焙,角色处于NavMesh范围内,未被判定为离网

内容的提问来源于stack exchange,提问作者thewebsitelearner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 02:45:36