前提
Unityにて、Charactor Controllerを使って二段ジャンプをしようと試みているのですが、1回目のジャンプの後、2回目をすると視点を変えても1回目と同じ方向に飛んで行ってしまいます。
実現したいこと
視点を変えたら2回目でも向いている方向に飛ぶ
該当のソースコード
if(jumpCount < 3 && Input.GetKeyDown(KeyCode.Space)){ moveDirection.y = jumpspeed; jumpCount++;
C#
ソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class WalkingMove : MonoBehaviour { private int jumpCount = 0; private float jumpspeed = 6.0f; public float speed = 10f; public float gravity = 20.0f; private CharacterController controller; private Vector3 moveDirection = Vector3.zero; private float h,v; void Start() { controller = GetComponent<CharacterController>(); } void Update() { h = Input.GetAxis("Horizontal"); v = Input.GetAxis("Vertical"); if(controller.isGrounded){ moveDirection = new Vector3(h,0,v); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; } **if(jumpCount < 3 && Input.GetKeyDown(KeyCode.Space)){** moveDirection.y = jumpspeed; jumpCount++; } moveDirection.y -= gravity * Time.deltaTime; controller.Move(moveDirection * Time.deltaTime); } ### 試したこと moveDirection.y = jumpspeed;のところを Vector3 jumpVec = new Vector3(0,jumpspeed,0); controller.Move(ju * Time.deltaTime); のようにほかのベクトルに置き換えてみたらカクカクして失敗しました。

回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/08/01 15:43