我一直在使用統一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);
}
}
}
}
幫助將深表讚賞後
是的,我有一個剛體組件。是的,我會盡力做出更改並儘快回覆。 –