提示画像では地面であるCubeのボックスコライダーのy軸を少し下げて地面と足の位置があうようにしていますがなぜ.Move()を使ってy軸を重力のようにmove.y = -20;しても隙間ができてしまうのでしょうか?プレイヤーのコリジョンの位置はぴったりプレイヤーにかぶさっていて四角いのコリジョンはキネマティックなので関係ありません。またどうすれば地面と合うように修正できるのでしょうか?
参考サイトは地面との接触判定ついての説明のため自分の欲しい情報ではありません。
参考サイト: http://inter-high-blog.unity3d.jp/2017/07/20/characongravity/
![イメー
using UnityEngine; public class Controller : MonoBehaviour { /* Ik 関係 Vector3 rightFootPos = new Vector3(0, 0, 0); Vector3 leftFootPos = new Vector3(0, 0, 0); Quaternion rightFootRot = new Quaternion(0, 0, 0, 0); Quaternion leftFootRot = new Quaternion(0, 0, 0, 0); bool isRightFootIK = false; bool isLeftFootIK = false; float RightIkWeight = 0; float LeftIkWeight = 0; Vector3 rayPositionOffset = new Vector3(0, 0, 0); float rayRange = 1.0f; float offset = 0.1f; */ private Vector3 vt; private float input_h; private float input_v; private Vector3 move; private float walk_speed;//移動速度 private Vector3 move_direction;//移動方向 private CharacterController cc; private Animator anim; /*判定*/ private bool isAttack = false; private bool isJump = false; private bool isGround = true; private AnimatorClipInfo[] ClipInfo; public GameObject p; private GameObject GroundCheck; public Transform LeftHand_IK;// //public GameObject LeftHand_target;// //private Transform LeftHand_IK = LeftHand_target; float j; // public GameObject groundCheck; // Use this for initialization void Start() { j = 0; move = new Vector3(0, 0, 0); cc = GetComponent<CharacterController>(); anim = GetComponent<Animator>(); walk_speed = 7; ClipInfo = anim.GetCurrentAnimatorClipInfo(0); GroundCheck = transform.Find("GroundCheck").gameObject; GroundCheck.GetComponent<Ground>().isGround = false; } 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.x = move_direction.x * walk_speed; move.z = move_direction.z * walk_speed; // Debug.Log("move.x: \n" + move.x); // Debug.Log("move.z: \n" + move.z); if (move_direction != Vector3.zero) { move_direction.y = 0; transform.rotation = Quaternion.LookRotation(move_direction.normalized); } /*ジャンプ*/ if(isJump == true) { Debug.Log("aaa"); // move.y += 2; }else //if (GroundCheck.GetComponent<Ground>().isGround == true) { } } void Animator_Mng() { anim.SetFloat("move_forward", getInput()); } float getSpeed() { return Mathf.Abs(Mathf.Sqrt(Mathf.Abs(move.x * move.x) + Mathf.Abs(move.z * move.z))); // return 100;//Mathf.Abs(Mathf.Sqrt( Mathf.Abs(move.x * move.x) + Mathf.Abs(move.z * move.z))); } float getInput() { return Mathf.Abs(Mathf.Sqrt(Mathf.Abs(input_h * input_h) + Mathf.Abs(input_v * input_v))); // return 100;//Mathf.Abs(Mathf.Sqrt( Mathf.Abs(move.x * move.x) + Mathf.Abs(move.z * move.z))); } //IKの重みを設定する void SetIkWeight(AvatarIKGoal _goal, float _posWeight, float _rotWeight) { anim.SetIKPositionWeight(_goal, Mathf.Clamp(_posWeight, 0.5f, 1.0f)); anim.SetIKRotationWeight(_goal, Mathf.Clamp(_rotWeight, 0.5f, 1.0f)); } //IKを指定して固定させる void SetIk(AvatarIKGoal goal, Vector3 _pos, Quaternion _rot, bool isAddIKPosition = false) { if (isAddIKPosition) _pos += anim.GetIKPosition(goal); anim.SetIKPosition(goal, _pos); anim.SetIKRotation(goal, _rot); } // Update is called once per frame void Update() { ClipInfo = anim.GetCurrentAnimatorClipInfo(0); /*ジャンプ処理*/ if ( Input.GetKey(KeyCode.Space) == true )//&& GroundCheck.GetComponent<Ground>().isGround == true && isJump == false) { Debug.Log("Jump"); // anim.SetTrigger("jump"); isJump = true; }else //if(isJump == true && GroundCheck.GetComponent<Ground>().isGround == false) { } if (Input.GetKeyDown(KeyCode.Z) == true && (ClipInfo[0].clip.name == "EllenIdle")) { anim.SetTrigger("attack_combo1"); Instantiate(p, transform.position, transform.rotation); } if (Input.GetKey(KeyCode.LeftShift) == true || Input.GetKey(KeyCode.RightShift) == true) { anim.SetBool("Run_shift", true); } else { anim.SetBool("Run_shift", false); } } ////////////////////////////////////////////////////////////////////////////////////////////// void FixedUpdate() { Move_Mng(); Animator_Mng(); move.y = - 20; cc.Move(move * Time.deltaTime); } ////////////////////////////////////////////////////////////////////////////////////////////// private void OnAnimatorIK() { Debug.Log("aaa"); anim.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1); anim.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1); anim.SetIKPosition(AvatarIKGoal.LeftHand, LeftHand_IK.position); anim.SetIKRotation(AvatarIKGoal.LeftHand, LeftHand_IK.rotation); /* //右手を固定 if (LeftHand_IK != null) { SetIkWeight(AvatarIKGoal.LeftHand, 1.0f, 1.0f); SetIk(AvatarIKGoal.LeftHand, LeftHand_IK.position, LeftHand_IK.rotation); } */ } void MeleeAttackStart() { } void MeleeAttackEnd() { } } /*
あなたの回答
tips
プレビュー