###発生している問題・エラーメッセージ
unityちゃんを移動させるスクリプトを、動かすアバターにつけたのですが、スクリプトの一部が実行されたり、実行されなかったりします。 以下のcospeedの値は画面上のジョイスティックを動かすと、数秒はインスペクタ上で値が変わるのですが、その後値が一定になります。 ジョイスティックを動かすのをやめて数秒待つとcospeedは0になり、また操作を受けつけるようになります。 ほかのh,v,sizeはインスペクタ上でジョイスティックを動かすたびに値を変えました。 またジョイスティックの作成には以下のサイトのスクリプトを利用させていただきました。 http://kan-kikuchi.hatenablog.com/entry/uGUI_Joystick_1
###該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class move : MonoBehaviour { public static int BattleLocoState = Animator.StringToHash("BattleLoco"); public static int BattleBackState = Animator.StringToHash("BattleBack"); //作成したJoystick [SerializeField] //privateフィールドをインスペクタに表示する際に付けるおまじない private Joystick _joystick = null; // 以下キャラクターコントローラ用パラメタ // 前進速度 public float forwardSpeed = 7.0f; // 後退速度 public float backwardSpeed = 2.0f; // 左右速度 public float LRSpeed = 2.0f; //速度補正値 public float cospeed; // ジャンプ威力 public float jumpPower = 3.0f; private Vector3 velocity; public float h; public float v; public float size; public Animator anim; private AnimatorStateInfo currentBaseState; // Use this for initialization void Start () { } // Update is called once per frame void FixedUpdate () { h = _joystick.Position.x; // 入力デバイスの水平軸をhで定義 v = _joystick.Position.y; // 入力デバイスの垂直軸をvで定義 currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // 参照用のステート変数にBase Layer (0)の現在のステートを設定する // 以下、キャラクターの移動処理 velocity = new Vector3(h, 0, v); // 上下左右のキー入力からxz平面の移動量を取得 velocity = transform.TransformDirection(velocity); // キャラクターのローカル空間での方向に変換 size = velocity.magnitude; anim.SetFloat("Speed", size); // Animator側で設定している"Speed"パラメタにSpeedを渡す anim.SetFloat("Direction", h); // Animator側で設定している"Direction"パラメタにhを渡す //idleとloco、back、jump以外で移動できないようにする。 if (currentBaseState.nameHash == playerinput.idleState | currentBaseState.nameHash == BattleLocoState | currentBaseState.nameHash == BattleBackState | currentBaseState.nameHash == playerinput.jumpState) { if (v > 0) { if (h > 0) { cospeed = LRSpeed * h + forwardSpeed * v; velocity *= cospeed; } else { cospeed = LRSpeed * -h + forwardSpeed * v; velocity *= cospeed; } } else if (v < 0) { if (h > 0) { cospeed = LRSpeed * h + forwardSpeed * -v; velocity *= cospeed; } else { cospeed = LRSpeed * -h + forwardSpeed * -v; velocity *= cospeed; } } else { if (h == 0) { cospeed = 0; velocity *= 0; } } } // 上下左右のキー入力でキャラクターを移動させる transform.localPosition += velocity * Time.fixedDeltaTime; } }
###試したこと
シーン上唯一のこのアバターにだけつけていたアニメーターを外すと問題なく動くようになりました。
アニメーターをつけても、https://www.mixamo.com/#/?page=1&query=idleの30fpsのアニメーションが実行されてる程度です。
###補足情報(言語/FW/ツール等のバージョンなど)
バージョンはUnity 2017.1.0f3 (64-bit)です。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。