【问题标题】:How to know end coordinates of animation in Unity?如何知道 Unity 中动画的结束坐标?
【发布时间】:2017-07-01 02:31:13
【问题描述】:

我想知道 Unity 动画结束时根骨骼的坐标。我试图以编程方式将带有 Animator 控制器的单元放到场景中,播放动画并多次执行 Update()。但坐标与真实坐标略有不同。 有没有办法在动画结束时知道准确的坐标?

更新。这段代码应该可以正常工作,但不能正常工作:

        animator.transform.position = new Vector3(0, 0, 0);
        animator.transform.rotation = Quaternion.Euler(0, 0, 0);            
        animator.Play(_hashName, 0, 0);
        AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
        duration = stateInfo.length;
        float t = 0;
        float delta = 0.01f;
        while (t < duration)
        {
            animator.Update(delta);
            t += delta;
        }
        Vector3 endCoords = animator.transform.position;

【问题讨论】:

  • 你能添加一些代码吗?
  • 将我的代码添加到问题中

标签: unity3d unity3d-mecanim


【解决方案1】:

我终于在 Unity3d 论坛上找到了绝妙的答案。

animator.SetTarget(AvatarTarget.Root, 1.0f);
animator.Update(0);
Vector3 position = animator.targetPosition;

效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 2020-09-07
    相关资源
    最近更新 更多