Unity 5 エンジンを使用してエンドレス ランナー ゲームに取り組んでおり、いくつかの例を研究しています。キャラクターにジャンプアクションを適用しました。うまくいきましたが、少し完璧にしたかったので、この例で曲線を使用してジャンプを埋め込み、この問題に遭遇しました。これは、いくつかの調整を行ってキャラクター コントローラーにカーブを適用した後です。ジャンプすると、プラットフォーム (地面) に触れた後、カーブがコントローラーの調整を開始し、ジャンプが非現実的になります。ゲームは基本的にフレームごとにすべてを更新する無限のランナーであるため、修正された Update メソッドを使用してジャンプを達成しようとしましたが、機能しませんでした。現実的なジャンプを実現するにはどうすればよいですか? 以下は私がこれまでに試したことです。
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);
}
}
}
}
助けていただければ幸いです