坂を上って下るときに地面この場合は坂道に張り付いて移動したいです、坂道を下るときに空中に浮いてから落下してしまい気持ちよくありません。重力はこれ以上強くしたくないので困っています。どうすればいいのでしょうか?
法線ベクトルを使って見舞いしたが変わりません。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { private Vector3 gravity; private Vector3 move; private Vector3 input; private Rigidbody rb; private const float gravity_speed = -10.0f; private const float walk_speed = 20.0f; private bool isJump; private bool isGround; private GameObject obj_ground; private Ground spt_ground;//地面判定 private Vector3 n; private Vector3 nomral; // Start is called before the first frame update void Start() { obj_ground = GameObject.Find("chr_ground"); spt_ground = obj_ground.GetComponent<Ground>(); isGround = false; isJump = false; gravity.y = gravity_speed; 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; //+ new Vector3(rb.velocity.x,0,rb.velocity.z); // move.y = gravity.y; n = Vector3.ProjectOnPlane(move,nomral); if (move != Vector3.zero) { Vector3 v = move; v.y = 0; transform.rotation = Quaternion.LookRotation(v.normalized); } } private void FixedUpdate() { rb.velocity = new Vector3(n.x, rb.velocity.y, n.z); rb.AddForce(gravity); if(isGround == true) { rb.velocity = new Vector3(n.x, 0, n.z); } } private void OnCollisionStay(Collision c) { nomral = c.contacts[0].normal; isGround = true; gravity.y = 0; //rb.velocity = new Vector3(rb.velocity.x, gravity.y, rb.velocity.z); } private void OnCollisionExit(Collision collision) { isGround = false; gravity.y = gravity_speed; } }

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/10/12 12:15
退会済みユーザー
2019/10/12 12:17
2019/10/12 12:21
退会済みユーザー
2019/10/12 12:23
2019/10/12 12:33
退会済みユーザー
2019/10/12 12:51
退会済みユーザー
2019/10/12 13:07
2019/10/12 13:29
退会済みユーザー
2019/10/12 15:29