前提
二段ジャンプできます。
実現したいこと
キーを押した長さに応じてジャンプする高さを変えたいです。
発生している問題・エラーメッセージ
ジャンプが終わった後に速度が不自然に減速したり、逆にそのまま飛べたりしてしまいます。
該当のソースコード
c#
1 void Update() 2 { 3 isGround = ground.IsGround(); 4 if (isGround == true) 5 { 6 isstage = 0; 7 } 8 9 if (Input.GetKeyDown(KeyCode.UpArrow)) 10 { 11 Jump(); 12 } 13 if (Input.GetKey(KeyCode.UpArrow)) 14 { 15 //ここが問題の箇所です。 16 if (timer + 0.3 >= Time.time & isstage < 2) 17 { 18 i.velocity = new Vector2(i.velocity.x, 1); 19 this.i.AddForce(transform.up * yspeed); 20 } 21 } 22 } 23 24 void Jump() 25 { 26 if (isstage < 1) 27 { 28 timer = Time.time; 29 Playercontroler.dashcan = true; 30 i.velocity = new Vector2(i.velocity.x, 1); 31 this.i.AddForce(transform.up * yspeed); 32 isstage++; 33 } 34 }}
試したこと
Time.deltaTimeをかけてみましたが、なんか違いました。
どうすればよいでしょうか。
回答2件
あなたの回答
tips
プレビュー