LoginSignup
9
10

More than 5 years have passed since last update.

ユニティちゃん歩く走るくつろぐ

Last updated at Posted at 2016-04-13

ユニティちゃん歩く走るくつろぐ

前回「ユニティちゃんを走らせてみた」からの変更点としては

・走らせ続けているのも(ユニティちゃんが)大変そうなので、ある程度ボールに近づいたら歩いてくつろぐように変更してみた。

動画

IMAGE ALT TEXT HERE

ダウンロード (Unityパッケージ)はこちら

Unity_FootstepsADX2LE_tatmos20160414

上記パッケージをインポートして自由に使っていただいて構いません。
ってか遊んでみてね。

歩かせるために

ターゲットまでの距離に応じて速度を変化させるようにしてみたり、休憩するモーション「Rest」に切り替えたりしてみた。
あとSpeedへ与える値も少し調整。

 MoveToTarget.cs
public class MoveToTarget : MonoBehaviour {
    public Transform target;
    NavMeshAgent agent;

    void Start () {
        Reset();
    }

    float lastMoveTime = 0f;

    void Update () {
        if(Time.timeSinceLevelLoad > lastMoveTime+0.1f)
        {
             GotoNextPoint();
            lastMoveTime = Time.timeSinceLevelLoad;
        }
        animator.SetFloat("Speed", agent.velocity.sqrMagnitude/40f);

        //Debug.Log(agent.remainingDistance );
        //  近いとゆっくり
        if (agent.remainingDistance < 2.5f)
        {
            agent.speed = 0;
            animator.SetTrigger("Rest");
        } else if (agent.remainingDistance < 10f)
        {
            agent.speed = 3.5f;
        } else {
            agent.speed = 6f;
        }
    }

    void GotoNextPoint()
    {
        agent.SetDestination(target.position);
    }

    [SerializeField, HideInInspector] Animator animator;

    void Reset()
    {
        agent = GetComponent<NavMeshAgent>();
        animator = GetComponent<Animator>();
    }
}

#ナビと戯れる

image

若干パラメータを変えている。
Stopping Distanceとかが近いと止まるみたい。

エージェントの移動とアニメーションの合わせるのちと大変かも

ちょこっと動いては止まるみたいな挙動などは何かしら抑制するように書かないといけないのか、Animetor側でトランジション調整するのか悩ましいところ。

あと、ナビメッシュのエージェント設定で動いているので、なんとなく速度は合わせたけど、
向きとか合わせる方法がなかなか難しい。

image

コライダー設定ミス?モーションの問題かな?

どうもジャンプモーションをさせると、位置がずれてしまうっぽくて、足音のトリガーがされなくなったりしてしまった。

image

あと、OnTriggerEnterで足音がなるけど、
床がPlaneだと、突き抜けたときに2回なりそうな気がするのでCubeに変えてみた。

image

9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10