c# - 如何使用曲线平滑地制作跳跃动画?

标签 c# animation unity3d curves

我一直在研究一些示例,使用 unity 5 引擎开发一款无尽的跑酷游戏。我对我的角色应用了跳跃 Action 。它确实工作得很好,但我希望它有点完美,所以我用这个 example 使用曲线植入了跳跃。 ,遇到了这个问题。那是在为角色 Controller 应用曲线并进行一些调整后,现在当我跳跃时,曲线在我接触平台(地面)后开始调整 Controller ,这使得跳跃变得不真实。我确实尝试使用固定更新方法实现跳跃,因为游戏是一个无尽的运行者,它基本上逐帧更新所有内容,但它不起作用。 如何实现逼真的跳跃?下面是我到目前为止尝试过的。

if (controller.isGrounded)
    {
        verticalVelocity = -0.5f; //upward thrust / jump height
            if (currentBaseState.fullPathHash == locoState) // is character in moving state
            {
                if (Input.GetButtonDown("Jump"))
                {
                    verticalVelocity = 18f;
                    anim.SetBool("Jump", true);
                }
            }
            else if (currentBaseState.fullPathHash == jumpState) //Is character in jump state
            {
                if (!anim.IsInTransition(0))
                {
                    if (useCurves)
                    {
                        controller.height = anim.GetFloat("ColliderHeight"); //get the controller height using curves
                        controller.center = new Vector3(0f, anim.GetFloat("ColliderY"), 0f); //Get the controller Y axis using the curves (center of chr ctrlr)
                    }

                    anim.SetBool("Jump", false);

                }
    // Applying curves
                Ray ray = new Ray(transform.position + Vector3.up, -Vector3.up);
                RaycastHit hitInfo = new RaycastHit();

                if (Physics.Raycast(ray, out hitInfo))
                {
                    print(ray.ToString());
                    if (hitInfo.distance > 1.75f)
                    {
                        anim.MatchTarget(hitInfo.point, Quaternion.identity, AvatarTarget.Root, new MatchTargetWeightMask(new Vector3(0, 1f, 0), 0), 0.03f, 0.6f);
                    }
                }    

            }
    }

Character jumping at start 开始时角色跳跃

Char controller touching the ground 触地的字符 Controller

Result after touching the ground 落地后的结果

帮助将不胜感激

最佳答案

根据曲线调整 Controller 的代码位于询问角色是否接地的 if 语句中。

if (controller.isGrounded)
{
 ...
}

这样它只会在角色接触地面时进行调整。

关于c# - 如何使用曲线平滑地制作跳跃动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38230342/

相关文章:

c# - 带有可折叠项目的 ListView?

c# - Azure 移动应用程序参与 Xamarin 身份验证

javascript - 按钮淡入淡出 jQuery ASP.net

c# - 使用全屏 View 作为幻灯片的 WPF 幻灯片

javascript - 检测each()中最后一个元素的动画结束

iphone - 连续旋转 UIImageView

c# - java中有类似LINQ的实现吗?

c# - Unity3D,如何在正确的线程中处理事件

c# - 如何停止默认动画?

unity3d - Hololens 空间理解 : Transferring coordinates from Unity WebGL app to Hololens Mixed Reality app