画像のようにジャンプ中で壁に向かって走ると画像のようになりキャラが落下しません。
個別で落下する処理を書きましたがうまく動作しないので質問しました
どうすれば実装できるのか教えてくれますでしょうか?
using System.Collections; using System.Collections.Generic; using UnityEngine; public class UnichanController: MonoBehaviour { private Animator anim; private Rigidbody rb; private const float moveSpeed = 3.0f; float inputHorizontal; float inputVertical; float speedx;//加速度x float speedz;//加速度y float speedy; bool isJump = false;//ジャンプ判定 bool isGround = false;//地面判定 RaycastHit hit; // Use this for initialization void Start () { anim = GetComponent<Animator>(); rb = GetComponent<Rigidbody>(); } void FixedUpdate() { // カメラの方向から、X-Z平面の単位ベクトルを取得 Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized; // 方向キーの入力値とカメラの向きから、移動方向を決定 Vector3 moveForward = (cameraForward * inputVertical) + (Camera.main.transform.right * inputHorizontal); // 移動方向にスピードを掛ける。ジャンプや落下がある場合は、別途Y軸方向の速度ベクトルを足す。 //rb.velocity = (moveForward * moveSpeed) + new Vector3(0, rb.velocity.y, 0); rb.velocity = (moveForward * moveSpeed) + new Vector3(0, rb.velocity.y, 0); // キャラクターの向きを進行方向に if (moveForward != Vector3.zero) { transform.rotation = Quaternion.LookRotation(moveForward); } // Key_Input(); // Debug.Log(rb.velocity.y); Animation_Mng();//アニメ管理 speedy = Mathf.Abs(rb.velocity.y); } //ジャンプ処理管理 int i = 0; void fjump(bool jump,bool ground) { if(jump == true && ground == true) { Debug.Log("jump"); rb.velocity = new Vector3(0,4.0f,0); isGround = false; isJump = false; i = 1; } if (jump == false && ground == false && i == 1)//落下 { rb.velocity = new Vector3(0,-1f,0); } i = 0; } // Update is called once per frame void Update () { Key_Input(); ray(); fjump(isJump, isGround); //Debug.Log(isGround); } void ray()//地面判定処理 { Ray ray = new Ray(transform.position, Vector3.down); if (Physics.Raycast(ray, out hit, 0.1f)) { if (hit.collider.tag == "isGround") { Debug.Log("ray"); isGround = true; isJump = false; } } } //キー入力管理 void Key_Input() { if (Input.GetKey(KeyCode.Space) && isGround == true) { //Debug.Log("key"); isJump = true; } inputHorizontal = Input.GetAxisRaw("Horizontal"); inputVertical = Input.GetAxisRaw("Vertical"); } void object_collision()//ブロック等に衝突してるときに進んだ場合の処理 { } //アニメーション管理クラス void Animation_Mng() { if(inputHorizontal != 0) { anim.SetBool("Run",true); } if (inputVertical != 0) { anim.SetBool("Run", true); } if (inputHorizontal == 0 && inputVertical == 0) { anim.SetBool("Run", false); } } private void OnCollisionEnter(Collision c) { string name = c.gameObject.tag; //地面判定 if("isGround" == name) { // Debug.Log("地面"); // isGround = true; rb.velocity = new Vector3(1,0,1); } } void CheckGround() { } }

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。