質問編集履歴
4
再度文章を編集
    
        title	
    CHANGED
    
    | @@ -1,1 +1,1 @@ | |
| 1 | 
            -
            IKが反応しない原因が知りたい
         | 
| 1 | 
            +
            IKが反応しない原因が知りたい スクリプト
         | 
    
        body	
    CHANGED
    
    | @@ -9,7 +9,9 @@ | |
| 9 9 |  | 
| 10 10 |  | 
| 11 11 | 
             
            質問ですが重さとはなんでしょうか?0~1の数値
         | 
| 12 | 
            +
            質問2 スクリプトをアタッチする場所をそのプレイヤーにアタッチしているのですがそもそもどこにアタッチすべきなのでしょうか?
         | 
| 12 13 |  | 
| 14 | 
            +
             | 
| 13 15 | 
             
            
         | 
| 14 16 | 
             
            
         | 
| 15 17 |  | 
3
文章とタイトルを編集
    
        title	
    CHANGED
    
    | @@ -1,1 +1,1 @@ | |
| 1 | 
            -
            IK | 
| 1 | 
            +
            IKが反応しない原因が知りたい
         | 
    
        body	
    CHANGED
    
    | @@ -1,19 +1,17 @@ | |
| 1 | 
            -
            IKを使って段差や斜面で足の裏が地面にく | 
| 1 | 
            +
            IKを使って段差や斜面で足の裏が地面に着くというIkの処理を実装したいのですが実装できませんどうしたらいいのでしょうか?
         | 
| 2 2 |  | 
| 3 3 |  | 
| 4 | 
            +
             | 
| 4 | 
            -
            1、ヒューマノイド | 
| 5 | 
            +
            1、ヒューマノイドです。
         | 
| 5 6 | 
             
            2、IK passにチェックを入れてる
         | 
| 6 | 
            -
            3、最低一つのアニメクリップが入ったアニメーションコントローラ | 
| 7 | 
            +
            3、最低一つのアニメクリップが入ったアニメーションコントローラを入れた
         | 
| 8 | 
            +
            4.カーブを作成し1にしている。二枚目の設定画像を参照
         | 
| 7 9 |  | 
| 8 10 |  | 
| 9 | 
            -
            質問 | 
| 11 | 
            +
            質問ですが重さとはなんでしょうか?0~1の数値
         | 
| 10 | 
            -
            質問2 Ikを使う場合コリジョンはどうすればいいのか知りたい
         | 
| 11 12 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 13 | 
             
            
         | 
| 16 | 
            -
            
         | 
| 17 15 |  | 
| 18 16 | 
             
            ```ここに言語を入力
         | 
| 19 17 | 
             
            using UnityEngine;
         | 
| @@ -23,7 +21,7 @@ | |
| 23 21 | 
             
            public class IK : MonoBehaviour
         | 
| 24 22 | 
             
            {
         | 
| 25 23 |  | 
| 26 | 
            -
                private CharacterController characterController;
         | 
| 24 | 
            +
                //private CharacterController characterController;
         | 
| 27 25 | 
             
                private Animator animator;
         | 
| 28 26 |  | 
| 29 27 | 
             
                // テスト用のIKのOn・Offスイッチ
         | 
| @@ -61,7 +59,7 @@ | |
| 61 59 |  | 
| 62 60 | 
             
                void Start()
         | 
| 63 61 | 
             
                {
         | 
| 64 | 
            -
             | 
| 62 | 
            +
                 //   characterController = GetComponent<CharacterController>();
         | 
| 65 63 | 
             
                    animator = GetComponent<Animator>();
         | 
| 66 64 | 
             
                }
         | 
| 67 65 |  | 
| @@ -70,15 +68,18 @@ | |
| 70 68 |  | 
| 71 69 | 
             
                    // 右足用のレイの視覚化
         | 
| 72 70 | 
             
                    Debug.DrawRay(animator.GetIKPosition(AvatarIKGoal.RightFoot), (-transform.up * rayRange), Color.red);
         | 
| 73 | 
            -
             | 
| 71 | 
            +
                //    Debug.Log(-transform.up * rayRange);
         | 
| 74 72 |  | 
| 75 73 |  | 
| 76 | 
            -
                    // 右足用のレイを飛ばす処理
         | 
| 77 74 | 
             
                    var ray = new Ray(animator.GetIKPosition(AvatarIKGoal.RightFoot), -transform.up);
         | 
| 78 75 | 
             
                    RaycastHit hit;
         | 
| 79 76 |  | 
| 77 | 
            +
             | 
| 78 | 
            +
                    /*右足用のレイを飛ばす処理*/
         | 
| 80 | 
            -
                    if (Physics.Raycast(ray, out hit, rayRange | 
| 79 | 
            +
                    if (Physics.Raycast(ray, out hit, rayRange))
         | 
| 81 80 | 
             
                    {
         | 
| 81 | 
            +
                        Debug.Log("右足 IK");
         | 
| 82 | 
            +
             | 
| 82 83 | 
             
                        rightFootPos = hit.point;
         | 
| 83 84 | 
             
                        rightFootRot = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
         | 
| 84 85 | 
             
                        isRightFootIK = true;
         | 
| @@ -88,14 +89,16 @@ | |
| 88 89 | 
             
                        isRightFootIK = false;
         | 
| 89 90 | 
             
                    }
         | 
| 90 91 |  | 
| 91 | 
            -
             | 
| 92 | 
            +
             | 
| 92 93 | 
             
                    ray = new Ray(animator.GetIKPosition(AvatarIKGoal.LeftFoot), -transform.up);
         | 
| 93 94 | 
             
                    // 左足用のレイの視覚化
         | 
| 94 95 | 
             
                    Debug.DrawRay(animator.GetIKPosition(AvatarIKGoal.LeftFoot), -transform.up * rayRange, Color.red);
         | 
| 95 96 |  | 
| 97 | 
            +
                    /*左足用のレイを飛ばす処理*/
         | 
| 96 98 |  | 
| 97 | 
            -
                    if (Physics.Raycast(ray, out hit, rayRange | 
| 99 | 
            +
                    if (Physics.Raycast(ray, out hit, rayRange))
         | 
| 98 100 | 
             
                    {
         | 
| 101 | 
            +
                        Debug.Log("左足 IK");
         | 
| 99 102 | 
             
                        leftFootPos = hit.point;
         | 
| 100 103 | 
             
                        leftFootRot = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
         | 
| 101 104 | 
             
                        isLeftFootIK = true;
         | 
| @@ -107,10 +110,11 @@ | |
| 107 110 | 
             
                    // IKを使う時だけ
         | 
| 108 111 | 
             
                    if (isUseIK)
         | 
| 109 112 | 
             
                    {
         | 
| 113 | 
            +
                        Debug.Log("IK");
         | 
| 110 114 | 
             
                        // アニメーションの状態からウエイトを取得
         | 
| 111 115 | 
             
                        rightFootWeight = animator.GetFloat("RightFootWeight");
         | 
| 112 116 | 
             
                        leftFootWeight = animator.GetFloat("LeftFootWeight");
         | 
| 113 | 
            -
             | 
| 117 | 
            +
                        /*右 IK*/
         | 
| 114 118 | 
             
                        if (isRightFootIK)
         | 
| 115 119 | 
             
                        {
         | 
| 116 120 |  | 
| @@ -121,12 +125,16 @@ | |
| 121 125 | 
             
                            // 右足の位置と角度を設定
         | 
| 122 126 | 
             
                            animator.SetIKPosition(AvatarIKGoal.RightFoot, rightFootPos + new Vector3(0f, offset, 0f));
         | 
| 123 127 | 
             
                            animator.SetIKRotation(AvatarIKGoal.RightFoot, rightFootRot);
         | 
| 128 | 
            +
                        
         | 
| 124 129 | 
             
                        }
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                        /*左 IK*/
         | 
| 125 132 | 
             
                        if (isLeftFootIK)
         | 
| 126 133 | 
             
                        {
         | 
| 127 134 | 
             
                            // 左足ウエイトの設定
         | 
| 128 135 | 
             
                            animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, leftFootWeight);
         | 
| 129 136 | 
             
                            animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, leftFootWeight);
         | 
| 137 | 
            +
             | 
| 130 138 | 
             
                            // 左足の位置と角度を設定
         | 
| 131 139 | 
             
                            animator.SetIKPosition(AvatarIKGoal.LeftFoot, leftFootPos + new Vector3(0f, offset, 0f));
         | 
| 132 140 | 
             
                            animator.SetIKRotation(AvatarIKGoal.LeftFoot, leftFootRot);
         | 
2
提示コードを変更、画像を追加、タイトルを編集
    
        title	
    CHANGED
    
    | @@ -1,1 +1,1 @@ | |
| 1 | 
            -
            IK | 
| 1 | 
            +
            IKを使って足元の段差を作りたい
         | 
    
        body	
    CHANGED
    
    | @@ -1,82 +1,137 @@ | |
| 1 1 | 
             
            IKを使って段差や斜面で足の裏が地面にくっついて移動という処理を作りたいのですがそもそもどう実装すればいいのでしょうか?
         | 
| 2 2 |  | 
| 3 | 
            +
             | 
| 3 4 | 
             
            1、ヒューマノイドじゃないとできない
         | 
| 4 5 | 
             
            2、IK passにチェックを入れてる
         | 
| 5 6 | 
             
            3、最低一つのアニメクリップが入ったアニメーションコントローラが必要
         | 
| 6 7 |  | 
| 7 8 |  | 
| 8 9 | 
             
            質問1 提示コードなのですがこれは何を設定してないのでしょうか?
         | 
| 10 | 
            +
            質問2 Ikを使う場合コリジョンはどうすればいいのか知りたい
         | 
| 9 11 |  | 
| 10 12 |  | 
| 11 13 |  | 
| 12 14 |  | 
| 13 15 | 
             
            
         | 
| 16 | 
            +
            
         | 
| 14 17 |  | 
| 15 | 
            -
             | 
| 16 18 | 
             
            ```ここに言語を入力
         | 
| 19 | 
            +
            using UnityEngine;
         | 
| 17 20 | 
             
            using System.Collections;
         | 
| 18 | 
            -
            using System.Collections.Generic;
         | 
| 19 | 
            -
            using  | 
| 21 | 
            +
            using System;
         | 
| 20 22 |  | 
| 21 23 | 
             
            public class IK : MonoBehaviour
         | 
| 22 24 | 
             
            {
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                private CharacterController characterController;
         | 
| 27 | 
            +
                private Animator animator;
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                // テスト用のIKのOn・Offスイッチ
         | 
| 30 | 
            +
                //[SerializeField]
         | 
| 31 | 
            +
                private bool isUseIK = true;
         | 
| 32 | 
            +
                // 右足のウエイト
         | 
| 33 | 
            +
                private float rightFootWeight = 0f;
         | 
| 34 | 
            +
                // 左足のウエイト
         | 
| 35 | 
            +
                private float leftFootWeight = 0f;
         | 
| 36 | 
            +
                // 右足の位置
         | 
| 37 | 
            +
                private Vector3 rightFootPos;
         | 
| 38 | 
            +
                // 左足の位置
         | 
| 39 | 
            +
                private Vector3 leftFootPos;
         | 
| 40 | 
            +
                // 右足の角度
         | 
| 41 | 
            +
                private Quaternion rightFootRot;
         | 
| 42 | 
            +
                // 左足の角度
         | 
| 43 | 
            +
                private Quaternion leftFootRot;
         | 
| 44 | 
            +
                // 足を付く位置のオフセット値
         | 
| 23 45 | 
             
                [SerializeField]
         | 
| 24 | 
            -
                private  | 
| 46 | 
            +
                private float offset = 0.1f;
         | 
| 47 | 
            +
                // レイを飛ばす距離
         | 
| 25 48 | 
             
                [SerializeField]
         | 
| 26 49 | 
             
                private float rayRange = 1f;
         | 
| 27 | 
            -
                [SerializeField]
         | 
| 28 | 
            -
                //private string fieldLayerName = "Field";
         | 
| 29 50 |  | 
| 51 | 
            +
                private bool isRightFootIK = false;
         | 
| 30 | 
            -
                private  | 
| 52 | 
            +
                private bool isLeftFootIK = false;
         | 
| 31 53 |  | 
| 54 | 
            +
                // コライダの位置を調整する時のスピード
         | 
| 55 | 
            +
                [SerializeField]
         | 
| 32 | 
            -
                private  | 
| 56 | 
            +
                private float smoothing = 2f;
         | 
| 33 | 
            -
                public new Transform transform
         | 
| 34 | 
            -
                {
         | 
| 35 | 
            -
                    get
         | 
| 36 | 
            -
                    {
         | 
| 37 | 
            -
                        if (_transform == null)
         | 
| 38 | 
            -
                        {
         | 
| 39 | 
            -
                            _transform = gameObject.transform;
         | 
| 40 | 
            -
                        }
         | 
| 41 | 
            -
                        return _transform;
         | 
| 42 | 
            -
                    }
         | 
| 43 | 
            -
                }
         | 
| 44 57 |  | 
| 58 | 
            +
                // レイを飛ばす位置の調整値
         | 
| 59 | 
            +
                [SerializeField]
         | 
| 60 | 
            +
                private Vector3 rayPositionOffset = Vector3.up * 0.3f;
         | 
| 45 61 |  | 
| 46 62 | 
             
                void Start()
         | 
| 47 63 | 
             
                {
         | 
| 64 | 
            +
                    characterController = GetComponent<CharacterController>();
         | 
| 48 65 | 
             
                    animator = GetComponent<Animator>();
         | 
| 49 66 | 
             
                }
         | 
| 50 67 |  | 
| 51 68 | 
             
                void OnAnimatorIK()
         | 
| 52 69 | 
             
                {
         | 
| 70 | 
            +
             | 
| 53 | 
            -
                    //右足
         | 
| 71 | 
            +
                    // 右足用のレイの視覚化
         | 
| 72 | 
            +
                    Debug.DrawRay(animator.GetIKPosition(AvatarIKGoal.RightFoot), (-transform.up * rayRange), Color.red);
         | 
| 73 | 
            +
                    Debug.Log(-transform.up * rayRange);
         | 
| 74 | 
            +
             | 
| 75 | 
            +
             | 
| 76 | 
            +
                    // 右足用のレイを飛ばす処理
         | 
| 54 77 | 
             
                    var ray = new Ray(animator.GetIKPosition(AvatarIKGoal.RightFoot), -transform.up);
         | 
| 55 78 | 
             
                    RaycastHit hit;
         | 
| 56 79 |  | 
| 57 | 
            -
                    if (Physics.Raycast(ray, out hit, rayRange))
         | 
| 80 | 
            +
                    if (Physics.Raycast(ray, out hit, rayRange, LayerMask.GetMask("Field")))
         | 
| 58 81 | 
             
                    {
         | 
| 82 | 
            +
                        rightFootPos = hit.point;
         | 
| 59 | 
            -
                         | 
| 83 | 
            +
                        rightFootRot = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                        //weightはとりあえず1で固定しておく(0f:元のアニメーション,1f:IKを完全に反映)
         | 
| 62 | 
            -
                         | 
| 84 | 
            +
                        isRightFootIK = true;
         | 
| 63 | 
            -
                        animator.SetIKRotationWeight(AvatarIKGoal.RightFoot, 1);
         | 
| 64 | 
            -
                        animator.SetIKPosition(AvatarIKGoal.RightFoot, hit.point + offset);
         | 
| 65 | 
            -
                        animator.SetIKRotation(AvatarIKGoal.RightFoot, rightRotation);
         | 
| 66 85 | 
             
                    }
         | 
| 86 | 
            +
                    else
         | 
| 87 | 
            +
                    {
         | 
| 88 | 
            +
                        isRightFootIK = false;
         | 
| 89 | 
            +
                    }
         | 
| 67 90 |  | 
| 68 | 
            -
                    //左足
         | 
| 91 | 
            +
                    // 左足用のレイを飛ばす処理
         | 
| 69 92 | 
             
                    ray = new Ray(animator.GetIKPosition(AvatarIKGoal.LeftFoot), -transform.up);
         | 
| 93 | 
            +
                    // 左足用のレイの視覚化
         | 
| 94 | 
            +
                    Debug.DrawRay(animator.GetIKPosition(AvatarIKGoal.LeftFoot), -transform.up * rayRange, Color.red);
         | 
| 95 | 
            +
             | 
| 96 | 
            +
             | 
| 70 | 
            -
                    if (Physics.Raycast(ray, out hit, rayRange))
         | 
| 97 | 
            +
                    if (Physics.Raycast(ray, out hit, rayRange, LayerMask.GetMask("Field")))
         | 
| 71 98 | 
             
                    {
         | 
| 99 | 
            +
                        leftFootPos = hit.point;
         | 
| 72 | 
            -
                         | 
| 100 | 
            +
                        leftFootRot = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
         | 
| 101 | 
            +
                        isLeftFootIK = true;
         | 
| 102 | 
            +
                    }
         | 
| 103 | 
            +
                    else
         | 
| 104 | 
            +
                    {
         | 
| 105 | 
            +
                        isLeftFootIK = false;
         | 
| 106 | 
            +
                    }
         | 
| 107 | 
            +
                    // IKを使う時だけ
         | 
| 108 | 
            +
                    if (isUseIK)
         | 
| 109 | 
            +
                    {
         | 
| 110 | 
            +
                        // アニメーションの状態からウエイトを取得
         | 
| 111 | 
            +
                        rightFootWeight = animator.GetFloat("RightFootWeight");
         | 
| 112 | 
            +
                        leftFootWeight = animator.GetFloat("LeftFootWeight");
         | 
| 73 113 |  | 
| 114 | 
            +
                        if (isRightFootIK)
         | 
| 115 | 
            +
                        {
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                            // 右足ウエイトの設定
         | 
| 118 | 
            +
                            animator.SetIKPositionWeight(AvatarIKGoal.RightFoot, rightFootWeight);
         | 
| 119 | 
            +
                            animator.SetIKRotationWeight(AvatarIKGoal.RightFoot, rightFootWeight);
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                            // 右足の位置と角度を設定
         | 
| 122 | 
            +
                            animator.SetIKPosition(AvatarIKGoal.RightFoot, rightFootPos + new Vector3(0f, offset, 0f));
         | 
| 123 | 
            +
                            animator.SetIKRotation(AvatarIKGoal.RightFoot, rightFootRot);
         | 
| 124 | 
            +
                        }
         | 
| 125 | 
            +
                        if (isLeftFootIK)
         | 
| 126 | 
            +
                        {
         | 
| 127 | 
            +
                            // 左足ウエイトの設定
         | 
| 74 | 
            -
             | 
| 128 | 
            +
                            animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, leftFootWeight);
         | 
| 75 | 
            -
             | 
| 129 | 
            +
                            animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, leftFootWeight);
         | 
| 130 | 
            +
                            // 左足の位置と角度を設定
         | 
| 76 | 
            -
             | 
| 131 | 
            +
                            animator.SetIKPosition(AvatarIKGoal.LeftFoot, leftFootPos + new Vector3(0f, offset, 0f));
         | 
| 77 | 
            -
             | 
| 132 | 
            +
                            animator.SetIKRotation(AvatarIKGoal.LeftFoot, leftFootRot);
         | 
| 133 | 
            +
                        }
         | 
| 78 134 | 
             
                    }
         | 
| 79 135 | 
             
                }
         | 
| 80 136 | 
             
            }
         | 
| 81 | 
            -
             | 
| 82 137 | 
             
            ```
         | 
1
タイトルを編集しました。
    
        title	
    CHANGED
    
    | @@ -1,1 +1,1 @@ | |
| 1 | 
            -
            IK | 
| 1 | 
            +
            IKで足元の段差の処理が反応しない(初心者)
         | 
    
        body	
    CHANGED
    
    | 
            File without changes
         | 
