提示コード部のFixedUpdate()部の提示画像のデバッグログの右の何回同じものが出力されたかという数字の部分ですが何故か移動中ににもかかわらずログが(0,0,0)で移動中にたまに(2.0,0,0)などといったおかしなログが出力されてしまうのでしょうか?rb.AddForceの後にDebug.Log()を載せているので直前の値が出力されるはずなのですが原因がわかりません。
質問内容:ログの値がおかしい原因と理由が知りたい。
質問内容2:move.x *= 100などのいった値がmoveに入っていながらも2.0といった値もなぜこんなに小さい値なのかも謎ですこれは正しい可能性もありますが気になったので質問しました。
Unityリファレンス: https://docs.unity3d.com/ja/2018.4/ScriptReference/Rigidbody-velocity.html
using System.Collections; using System.Collections.Generic; 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; GameObject Ground; /*坂道計算*/ GameObject Slope; [SerializeField] Vector3 slope_range = new Vector3(0, 0, 0); // Use this for initialization void Start() { Ground = GameObject.Find("GroundCheck"); Slope = GameObject.Find("SlopeCheck"); walk_speed = 5.0f; gravity = Vector3.zero; rb = GetComponent<Rigidbody>(); ani = GetComponent<Animator>(); } void Gravity_Mng()//ジャンプ管理 { } void Slope_Mng()//坂道 { RaycastHit hit; Vector3 forward = transform.forward + slope_range; Debug.DrawLine(Slope.transform.position, Slope.transform.position + forward ,Color.blue); // float speed = Mathf.Sqrt((move.x * move.x) + (move.z * move.z)); float speed = Mathf.Sqrt((rb.velocity.x * rb.velocity.x) + (rb.velocity.z * rb.velocity.z)); if(speed != 0){ if(Physics.Linecast(Slope.transform.position, Slope.transform.position + forward, out hit,LayerMask.GetMask("Slope")) == true) { Debug.Log("坂道のRayヒット!"); v = new Vector3(0f, (Quaternion.FromToRotation(Vector3.up, hit.normal) * transform.forward * speed).y, 0f) + transform.forward * speed; Debug.Log("v.y: "+ v.y); } }else{ v.y = 0; } } 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 = move_x + move_z; if (move != Vector3.zero) { transform.rotation = Quaternion.LookRotation(move.normalized); } move.x *= 100; move.z *= 100; } // Update is called once per frame void Update() { Gravity_Mng(); Slope_Mng(); Move_Mng(); // Debug.Log("velocity: " + Mathf.Sqrt((rb.velocity.x * rb.velocity.x) + (rb.velocity.z * rb.velocity.z))); } ////////////////////////////////////////////////////////////////////////////////////////////// void FixedUpdate() { rb.AddForce(move.x, 0, move.z); Debug.Log("velocity: " + rb.velocity); } ////////////////////////////////////////////////////////////////////////////////////////////// }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。