質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Q&A

0回答

459閲覧

移動しながらジャンプするときと止まっているときにジャンプするときで上昇量が違う原因が知りたい。

退会済みユーザー

退会済みユーザー

総合スコア0

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

0グッド

0クリップ

投稿2020/02/07 12:33

タイトル通りなのでですがジャンプするときに動いているときと停止しているときで上昇量がものすごい変化するのですがこれはどうしたらいいのでしょうか?どこが原因なのか検討がつきません。

Controller.cs

public class Controller : MonoBehaviour { private float input_h; private float input_v; private Vector3 move; private Rigidbody rb; private float walk_speed;//移動速度 private Animator ani;//移動速度 private Vector3 gravity; private bool isJump = false;//ジャンプしてるかどうかを管理する private Vector3 v = new Vector3(0,-60.0f,0); private bool isAttack; GameObject cg; Ground ground_sct; // Use this for initialization void Start () { cg = GameObject.Find("GroundCheck"); ground_sct = cg.GetComponent<Ground>(); isAttack = false; walk_speed = 10.0f; gravity = Vector3.zero; rb = GetComponent<Rigidbody>(); ani = GetComponent<Animator>(); } void Animation_Mng() { float f = Mathf.Abs(Mathf.Sqrt(move.x * move.x + move.z * move.z)); //float f = 0; //Debug.Log(f); ani.SetFloat("Forward",f);///////////移動 } void Gravity_Mng()//ジャンプ { Debug.Log(ground_sct.isGround); if (Input.GetKeyDown("space") == true && ground_sct.isGround == true) { gravity.y = 100; ground_sct.isGround = false; Debug.Log("ジャンプ"); } } void Attack_Mng()//攻撃管理 { if(Input.GetMouseButtonDown(0) == true) { Debug.Log("左クリック(攻撃)"); ani.SetBool("isAttack",true); }else{ ani.SetBool("isAttack", false); } } // Update is called once per frame void Update () { Animation_Mng(); Gravity_Mng(); Attack_Mng(); input_h = Input.GetAxis("Horizontal"); input_v = Input.GetAxis("Vertical"); Vector3 move_x = new Vector3(); Vector3 move_z = new Vector3(); move_z = Vector3.Scale(Camera.main.transform.forward , new Vector3(1, 0, 1)).normalized * input_v * walk_speed;//Z move_x = Camera.main.transform.right * input_h * walk_speed;//X move = move_x + move_z; move.y = 0; Debug.Log(move.y); if(move != Vector3.zero){ transform.rotation = Quaternion.LookRotation(move.normalized); } } void FixedUpdate() { // rb.velocity = new Vector3(move.x,rb.velocity.y,move.z); if (ground_sct.isGround == false) { gravity.y += -4; } else { gravity.y = 0; } rb.AddForce(0,gravity.y,0); // rb.velocity = new Vector3(move.x,rb.velocity.y,move.z); }

Ground.cs

using System.Collections; using System.Collections.Generic; using UnityEngine; /* * キー入力とジャンプ処理 * */ public class Ground : MonoBehaviour { public bool isGround = true; // Start is called before the first frame update void Start() { isGround = true; } // Update is called once per frame void Update() { } private void FixedUpdate() { } private void OnTriggerEnter() { isGround = true; } private void OnTriggerStay() { } private void OnTriggerExit() { isGround = false; } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問