2016-07-06 73 views
2

我一直在使用统一5引擎学习一些例子的无尽亚军游戏。我将跳跃动作应用于我的角色。它确实工作正常,但我希望它有点完美,所以我使用这种example曲线植入跳跃,遇到了这个问题。即在对角色控制器应用曲线进行一些调整之后,现在当我跳跃时,在我触及跳跃的平台(地面)之后,开始调整控制器的曲线不切实际。我确实尝试过使用固定更新方法来实现跳转,因为游戏是一个无尽的跑步者,它基本上逐帧更新所有的帧,它不起作用。 我该如何实现真实的跳跃?下面是我到目前为止所尝试的。如何使用曲线平滑地跳转动画?

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 字符控制器接触地面

Result after touching the ground 结果触地

帮助将深表赞赏后

回答

1

根据曲线调整控制器的代码位于if语句中,询问字符是否接地。

if (controller.isGrounded) 
{ 
... 
} 

那样它只会在角色触地时才会调整。

0

你的游戏对象有刚体吗?如果不是,则尝试添加并使刚体成为无运动体,因为当您使用碰撞体移动物体而没有刚体时,需要重新计算完整的静态碰撞数据,这很慢。 或者,可能会尝试玩动画跳帧率不要太小

+0

是的,我有一个刚体组件。是的,我会尽力做出更改并尽快回复。 –