地面に押し付ける重力がAddForceです。斜面を下るときに空中に浮いてから重力の処理が入ってしまうため空中に浮いてしまいますこれはどうすればいいのでしょうか?落下重力はこのままでジャンプと落下以外は地面に沿って移動したいのですが
※詳細に説明しますとまず斜面を下ろうと画面から見て後ろにキーを押すとy軸を無視して空中に浮いて(提示画像)そっからy軸に重力落下するのです。重力の値を-50.0fにしまたが落ちるのが早いだけで何も変わりませんこれは何をしたのでしょうか?
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { private Vector3 move; private Vector3 gravity; private Vector3 input; private Rigidbody rb; private const float walk_speed = 20.0f; private bool isJump; private bool isGround; // Start is called before the first frame update void Start() { gravity.y = -10.0f; isGround = false; isJump = false; rb = GetComponent<Rigidbody>(); } // Update is called once per frame void Update() { input.x = Input.GetAxis("Horizontal"); input.z = Input.GetAxis("Vertical"); Vector3 move_z; Vector3 move_x; move_z = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized * input.z * walk_speed; move_x = Camera.main.transform.right * input.x * walk_speed; move = move_x + move_z; if (move != Vector3.zero) { Vector3 v = move; v.y = 0; transform.rotation = Quaternion.LookRotation(v.normalized); } } private void FixedUpdate() { if(isGround == false) { } else { } rb.AddForce(gravity); rb.velocity = new Vector3(move.x, rb.velocity.y, move.z); } private void OnCollisionEnter(Collision collision) { // isGround = true; // gravity.y = 0; // rb.velocity = new Vector3(rb.velocity.x, gravity.y, rb.velocity.z); } private void OnCollisionStay(Collision c) { //move.y = 0; rb.velocity = new Vector3(move.x, 0, move.z); } private void OnCollisionExit(Collision c) { isGround = false; } }
ふと思ったのですが、モデルのコライダーの形は何ですか?
普通はカプセル型だと思いますが、念のため。
あなたの回答
tips
プレビュー