タイトル通りなのでですがジャンプするときに動いているときと停止しているときで上昇量がものすごい変化するのですがこれはどうしたらいいのでしょうか?どこが原因なのか検討がつきません。
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; } }
あなたの回答
tips
プレビュー