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

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

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

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

Q&A

0回答

467閲覧

坂道を上るりキーを離すと上に上がってしまう原因を解決したい

退会済みユーザー

退会済みユーザー

総合スコア0

Unity3D

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

0グッド

0クリップ

投稿2019/10/24 10:47

編集2019/10/28 11:19

坂道を上りり方向キーを離すと上に上がってしまう原因を解決したいです、また坂を下るときに動いてから重力が働き落下するという不自然な処理が出来上がってしまうのですがどうすればいいのでしょうか?
コリジョンはメッシュコライダーでuse gravityは切っています。

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { Rigidbody rb; Vector3 move; float input_h; float input_v; Vector3 move_x; Vector3 move_y; public GameObject gGround; ground spt_g; bool isJump; bool isDush; float jump_force = 200.0f; const float move_speed = 5.0f; Animator ani; // GameObject go = GameObject.Find("GameObject"); // Start is called before the first frame update void Start() { rb = GetComponent<Rigidbody>(); spt_g = gGround.GetComponent<ground>(); ani = GetComponent<Animator>(); isJump = false; isDush = false; } // Update is called once per frame void Update() { input_h = Input.GetAxis("Horizontal"); input_v = Input.GetAxis("Vertical"); move_y = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized * input_v * move_speed; move_x = Camera.main.transform.right * input_h * move_speed; move = move_x + move_y; if(move != Vector3.zero) { transform.rotation = Quaternion.LookRotation(move.normalized); } if(Input.GetKey(KeyCode.RightControl)) { //isDush = true; } if(Input.GetKey(KeyCode.Space)) { if(spt_g.isGround == true && isJump == false) { isJump = true; } } Animation_Mng(); } /*アニメーション管理*/ void Animation_Mng() { float speed = Mathf.Sqrt((move.x * move.x) + (move.z * move.z)); ani.SetFloat("Move_Speed",speed); } private void FixedUpdate() { rb.velocity = new Vector3(move.x, rb.velocity.y, move.z); if(isJump == true) { rb.AddForce(rb.velocity.x,jump_force,rb.velocity.z); isJump = false; // spt_g.isGround = false; } else { } if(spt_g.isGround == false) { rb.AddForce(new Vector3(0, -10.0f, 0)); } else { rb.AddForce(new Vector3(rb.velocity.x, 0, rb.velocity.z)); } if(input_h == 0 && input_v == 0) { //rb.velocity = new Vector3(0, rb.velocity.y, 0); } } private void OnCollisionEnter(Collision collision) { // Debug.Log("プレイヤーcollision"); } }

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問