提示コードのFiexedUpdate()とOnCollisionStay()関数の処理の順番が知りたいです。move.yには確実に値が入っているはずなのですが何かの順序?の違いでmove.yが0になってしまっているOnCollisionStay()とFixedUpdate()の実行順序に違いで何か起きているものと考えられるのですが?
質問 コーディングミスなのか順序のよる違いなのか知りたい。
実現するはずの処理内容
コリジョンに当たっているベクトルから平面ベクトルを求めて地面にそって移動するプログラム
using UnityEngine; 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; private bool isDush; private Vector3 move_direction;//移動方向 // private CharacterController cc; GameObject ground_ray; /*坂道計算*/ GameObject forward_ray; [SerializeField] float slope_range; [SerializeField] Vector3 slope_direc = new Vector3(0, 0, 0); [SerializeField] Vector3 slope_direc_b = new Vector3(0, 0, 0); GameObject contacts; // [SerializeField] Vector3 slope_pos; // Use this for initialization void Start() { ground_ray = GameObject.Find("GroundCheck"); forward_ray = GameObject.Find("SlopeCheck"); contacts = GameObject.Find("contacts"); // cc = GetComponent<CharacterController>(); forward_ray.transform.position = slope_pos + forward_ray.transform.position; walk_speed = 100; gravity = Vector3.zero; rb = GetComponent<Rigidbody>(); ani = GetComponent<Animator>(); } void Gravity_Mng()//ジャンプ管理 { } void Move_Mng() { input_h = Input.GetAxis("Horizontal"); input_v = Input.GetAxis("Vertical"); Vector3 move_z = new Vector3(); Vector3 move_x = new Vector3(); move_z = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized * input_v; move_x = Camera.main.transform.right * input_h; move_direction = move_x + move_z; move_direction.y = 0; move = move_direction * walk_speed; if (move_direction != Vector3.zero) { move_direction.y = 0; transform.rotation = Quaternion.LookRotation(move_direction.normalized); } } float getSpeed() { return Mathf.Abs(Mathf.Sqrt(move.x * move.x + move.z * move.z)); } // Update is called once per frame void Update() { Gravity_Mng(); Move_Mng(); Debug.Log(" update move.y: " + move.y); } ////////////////////////////////////////////////////////////////////////////////////////////// void FixedUpdate() { // rb.AddForce(move.x, move.y, move.z); rb.AddForce(move.x,move.y,move.z); Debug.Log(" Fixed move.y: " + move.y); } ////////////////////////////////////////////////////////////////////////////////////////////// /**/ private void OnCollisionStay(Collision collision) { // Debug.Log("OnCollisionStay: " + collision.contacts[0].point); contacts.transform.position = collision.contacts[0].point; // Debug.Log("あああああ"); Vector3 f = transform.forward; Vector3 vv = collision.contacts[0].normal; Vector3 dir = f - Vector3.Dot(f, vv) * vv; f = dir.normalized * walk_speed;//y軸だけ使う move.y = f.y; Debug.Log("f: " + move.y); } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。