unity3d Unity 3D上的跳跃动画

efzxgjgh  于 2023-04-07  发布在  其他
关注(0)|答案(1)|浏览(187)

我有一个问题,我不知道如何使动画逻辑,也许如何团结剪辑之间的Animation tree where, each transition on jump is like Isjumping = true, then IsFalling = true etc.And if needed, my jump script

RaycastHit hit;
        bool isFalling = Physics.Raycast(transform.position, transform.TransformDirection(Vector3.Normalize(_controller.velocity)), out hit, Mathf.Infinity, 1);
        _animator.SetBool(_isJumpingHash, !_isGrounded);

        if (isFalling)
        {
            if (hit.distance >= _raycastDistance && transform.TransformDirection(Vector3.Normalize(_controller.velocity)).y <= 0)
            {
                _animator.SetBool(_isFallingHash, true);
            }
            else
            {
                _animator.SetBool(_isLandingHash, true);
            }
        }

这是当前的汉尔德跳跃动画,但它不工作。
我的脚本是基于CharacterController的,我该怎么办?
我尝试了不同的方法从互联网上,但我的动画是不工作

ruarlubt

ruarlubt1#

虽然你的这个问题很宽泛,并没有涉及到一个具体的问题,这就是我标记它的原因。但是我想提醒你的关键点肯定会对你有用。正如你所知道的,随着动画师的发展,这种为每个状态创建参数的方法使得工作更加困难和复杂。所以你需要一种参数化的方法来保持动态,并在不同的部分为你工作。现在看看下面的代码。

[SerializeField] private LayerMask groundLayer;
private bool _isGrounded;
void Update()
{
    _isGrounded = Physics.Raycast(transform.position, -transform.up, out var hit, 1, groundLayer.value);

    if (Input.GetKeyDown(KeyCode.Space)) 
    {
        // jump is Trigger cuz is playing once when pressing key
        _animator.SetTrigger(_isJumpingHash);
    }

    // set Y velocity as float to animator to make it dynamic
    _animator.SetFloat("yVelocity", _controller.velocity.y); 
    // The presence of isGrounded in the animator itself is also useful and prevents possible bugs along with other conditions.
    _animator.SetBool("isGrounded", _isGrounded);
}

上面我尝试直接将yVelocity传递给animator,而不是为isFalling取布尔值。因为这使你在animator中有更多的自由。例如,如果下降速度增加,我们可以切换到另一个动画,或者isFalling动画将自动工作的任何其他地方。现在已经足够确定可以在animator中输入的状态。

  • 跳转移动状态(甚至空闲)下,设置下降条件如下(yVelocity小于-.1)。
  • 对于跳转(或任何一次动作行为),只需创建一个Trigger,并在按下跳转键时设置。
  • 对于着陆,将isGrounded设置为animator并为其设置相同的条件。
  • 除了从【着陆】状态退出到【移动】状态的条件外,其他条件均禁用hasExitTime

相关问题