2016-07-06 49 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

是的,我有一個剛體組件。是的,我會盡力做出更改並儘快回覆。 –